Sha256: 677a9906c01efd2631a40b4ec0d3bad709ebc69460318a548bba6e51478c2fa0
Contents?: true
Size: 749 Bytes
Versions: 2
Compression:
Stored size: 749 Bytes
Contents
module Celluloid # Allow methods to directly interact with the actor protocol class Receivers def initialize @handlers = [] end # Receive an asynchronous message def receive(&block) raise ArgumentError, "receive must be given a block" unless block @handlers << [Fiber.current, block] Fiber.yield end # Handle incoming messages def handle_message(message) handler = nil @handlers.each_with_index do |(fiber, block), index| if block.call(message) handler = index break end end if handler fiber, _ = @handlers.delete_at handler fiber.resume message true else false end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
celluloid-0.6.2 | lib/celluloid/receivers.rb |
celluloid-0.6.1 | lib/celluloid/receivers.rb |