Class: Celluloid::Proxy::Future

Inherits:
Abstract
  • Object
show all
Defined in:
lib/celluloid/proxy/future.rb

Overview

A proxy which creates future calls to an actor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox, klass) ⇒ Future

Returns a new instance of Future.



10
11
12
13
# File 'lib/celluloid/proxy/future.rb', line 10

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/celluloid/proxy/future.rb', line 19

def method_missing(meth, *args, &block)
  unless @mailbox.alive?
    fail ::Celluloid::DeadActorError, "attempted to call a dead actor"
  end

  if block_given?
    # FIXME: nicer exception
    fail "Cannot use blocks with futures yet"
  end

  future = ::Celluloid::Future.new
  call = ::Celluloid::Call::Sync.new(future, meth, args, block)

  @mailbox << call

  future
end

Instance Attribute Details

#mailboxObject (readonly)

Returns the value of attribute mailbox.



3
4
5
# File 'lib/celluloid/proxy/future.rb', line 3

def mailbox
  @mailbox
end

Instance Method Details

#__class__Object

Used for reflecting on proxy objects themselves



6
7
8
# File 'lib/celluloid/proxy/future.rb', line 6

def __class__
  ::Celluloid::Proxy::Future
end

#inspectObject



15
16
17
# File 'lib/celluloid/proxy/future.rb', line 15

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