File: block.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (28 lines) | stat: -rw-r--r-- 686 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Celluloid::Proxy::Block
  attr_writer :execution
  attr_reader :call, :block

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

  def to_proc
    if @execution == :sender
      lambda do |*values|
        if task = Thread.current[:celluloid_task]
          @mailbox << ::Celluloid::Call::Block.new(self, ::Celluloid::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