Class: Celluloid::AsyncProxy

Inherits:
AbstractProxy show all
Defined in:
lib/celluloid/proxies/async_proxy.rb

Overview

A proxy which sends asynchronous calls to an actor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox, klass) ⇒ AsyncProxy

Returns a new instance of AsyncProxy.


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

def initialize(mailbox, klass)
  @mailbox, @klass = mailbox, klass
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/celluloid/proxies/async_proxy.rb', line 17

def method_missing(meth, *args, &block)
  if @mailbox == ::Thread.current[:celluloid_mailbox]
    args.unshift meth
    meth = :__send__
  end

  if block_given?
    # FIXME: nicer exception
    raise "Cannot use blocks with async yet"
  end

  @mailbox << AsyncCall.new(meth, args, block)
end

Instance Attribute Details

#mailboxObject (readonly)

Returns the value of attribute mailbox


4
5
6
# File 'lib/celluloid/proxies/async_proxy.rb', line 4

def mailbox
  @mailbox
end

Instance Method Details

#__class__Object

Used for reflecting on proxy objects themselves


7
# File 'lib/celluloid/proxies/async_proxy.rb', line 7

def __class__; AsyncProxy; end

#inspectObject


13
14
15
# File 'lib/celluloid/proxies/async_proxy.rb', line 13

def inspect
  "#<Celluloid::AsyncProxy(#{@klass})>"
end