Class: Zold::SyncEntrance

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/node/sync_entrance.rb

Overview

The entrance that makes sure only one thread works with a wallet

Instance Method Summary collapse

Constructor Details

#initialize(entrance, dir, timeout: 30, log: Log::NULL) ⇒ SyncEntrance

Returns a new instance of SyncEntrance.



36
37
38
39
40
41
# File 'lib/zold/node/sync_entrance.rb', line 36

def initialize(entrance, dir, timeout: 30, log: Log::NULL)
  @entrance = entrance
  @dir = dir
  @timeout = timeout
  @log = log
end

Instance Method Details

#push(id, body) ⇒ Object

Always returns an array with a single ID of the pushed wallet



59
60
61
62
63
# File 'lib/zold/node/sync_entrance.rb', line 59

def push(id, body)
  Futex.new(File.join(@dir, id), log: @log, timeout: 60 * 60).open do
    @entrance.push(id, body)
  end
end

#startObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/zold/node/sync_entrance.rb', line 47

def start
  raise 'Block must be given to start()' unless block_given?
  if File.exist?(@dir)
    FileUtils.rm_rf(@dir)
    @log.info("Directory #{@dir} deleted")
  end
  @entrance.start do
    yield(self)
  end
end

#to_jsonObject



43
44
45
# File 'lib/zold/node/sync_entrance.rb', line 43

def to_json
  @entrance.to_json
end