Sha256: 0ccea4af8b4209e1ccbc30a8f8f5fafb8e2450528cff81dd318f9a405473a08f
Contents?: true
Size: 638 Bytes
Versions: 4
Compression:
Stored size: 638 Bytes
Contents
module Celluloid # Event signaling between methods of the same object class Signals def initialize @waiting = {} end # Wait for the given signal name and return the associated value def wait(name) fibers = @waiting[name] ||= [] fibers << Fiber.current Fiber.yield end # Send a signal to all method calls waiting for the given name # Returns true if any calls were signaled, or false otherwise def send(name, value = nil) fibers = @waiting.delete name return unless fibers fibers.each { |fiber| fiber.resume value } true end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
celluloid-0.5.0 | lib/celluloid/signals.rb |
celluloid-0.2.2 | lib/celluloid/signals.rb |
celluloid-0.2.1 | lib/celluloid/signals.rb |
celluloid-0.2.0 | lib/celluloid/signals.rb |