Class: Celluloid::BlockProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/proxies/block_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(call, mailbox, block) ⇒ BlockProxy

Returns a new instance of BlockProxy.


3
4
5
6
7
8
# File 'lib/celluloid/proxies/block_proxy.rb', line 3

def initialize(call, mailbox, block)
  @call = call
  @mailbox = mailbox
  @block = block
  @execution = :sender
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block


10
11
12
# File 'lib/celluloid/proxies/block_proxy.rb', line 10

def block
  @block
end

#callObject (readonly)

Returns the value of attribute call


10
11
12
# File 'lib/celluloid/proxies/block_proxy.rb', line 10

def call
  @call
end

#execution=(value) ⇒ Object (writeonly)

Sets the attribute execution

Parameters:

  • value

    the value to set the attribute execution to.


9
10
11
# File 'lib/celluloid/proxies/block_proxy.rb', line 9

def execution=(value)
  @execution = value
end

Instance Method Details

#to_procObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/celluloid/proxies/block_proxy.rb', line 12

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