Sha256: 3f354538b05ca937c16dd172e86907e48feaa9a20599738697828a0852fa3af6
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
require "agent/errors" module Agent class Pop attr_reader :uuid, :blocking_once, :notifier, :object def initialize(options={}) @object = nil @uuid = options[:uuid] || UUID.generate @blocking_once = options[:blocking_once] @notifier = options[:notifier] @mutex = Mutex.new @cvar = ConditionVariable.new @received = false @closed = false end def received? @received end def closed? @closed end def wait @mutex.synchronize do until @received || @closed @cvar.wait(@mutex) end return false if @closed received? end end def send @mutex.synchronize do if @blocking_once _, error = @blocking_once.perform do @object = yield unless @closed @received = true @cvar.signal @notifier.notify(self) if @notifier end return error else begin @object = yield unless @closed @received = true @cvar.signal @notifier.notify(self) if @notifier rescue Errors::Rollback end end end end def close @mutex.synchronize do return if @received @closed = true @cvar.broadcast @notifier.notify(self) if @notifier end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
agent-0.12.0 | lib/agent/pop.rb |