class Zold::SyncEntrance

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

Public Class Methods

new(entrance, dir, timeout: 30, log: Log::NULL) click to toggle source
# 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

Public Instance Methods

push(id, body) click to toggle source

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

# 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
start() { |self| ... } click to toggle source
# 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_json() click to toggle source
# File lib/zold/node/sync_entrance.rb, line 43
def to_json
  @entrance.to_json
end