Sha256: 4b307c833c27a4741af77a732f2cb62b2e08f78d5041b9b546db022d91d6ea80

Contents?: true

Size: 717 Bytes

Versions: 21

Compression:

Stored size: 717 Bytes

Contents

module Celluloid
  class BlockProxy
    def initialize(call, mailbox, block)
      @call = call
      @mailbox = mailbox
      @block = block
      @execution = :sender
    end
    attr_writer :execution
    attr_reader :call, :block

    def to_proc
      if @execution == :sender
        lambda do |*values|
          if task = Thread.current[:celluloid_task]
            @mailbox << BlockCall.new(self, Actor.current.mailbox, values)
            # TODO: if respond fails, the Task will never be resumed
            task.suspend(:invokeblock)
          else
            # FIXME: better exception
            raise "No task to suspend"
          end
        end
      else
        @block
      end
    end
  end
end

Version data entries

21 entries across 19 versions & 6 rubygems

Version Path
celluloid-0.14.0.pre lib/celluloid/proxies/block_proxy.rb