Sha256: 5895a8200c0c5e0bda1edb9ca71ab55d17d3bd5d40e8d8f9d3c7f447a5444477
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 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 received? end end def send @mutex.synchronize do raise Errors::ChannelClosed if @closed if @blocking_once _, error = @blocking_once.perform do @object = Marshal.load(yield) @received = true @cvar.signal @notifier.notify(self) if @notifier end return error else begin @object = Marshal.load(yield) @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.9.1 | lib/agent/pop.rb |