Class: Probject::Actor
- Inherits:
-
Object
- Object
- Probject::Actor
- Defined in:
- lib/probject/actor.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#async ⇒ Object
(also: #tell)
asynchronous call returns nil.
-
#future ⇒ Object
(also: #ask)
asynchronous call returns Probject::Future.
-
#initialize ⇒ Actor
constructor
A new instance of Actor.
- #pid ⇒ Object
- #terminate(timeout = 10) ⇒ Object
- #terminated? ⇒ Boolean
Constructor Details
#initialize ⇒ Actor
Returns a new instance of Actor.
9 10 11 12 13 14 15 16 |
# File 'lib/probject/actor.rb', line 9 def initialize @____request_channel = IChannel.new Marshal response_channel = IChannel.new Marshal @____response_handler = ResponseHandler.new response_channel @____pid = Actor.spawn self, @____request_channel, response_channel ObjectSpace.define_finalizer(self, self.class.finalize(@____pid)) end |
Class Method Details
.finalize(pid) ⇒ Object
58 59 60 |
# File 'lib/probject/actor.rb', line 58 def self.finalize(pid) proc { self.kill pid } end |
Instance Method Details
#async ⇒ Object Also known as: tell
asynchronous call returns nil
44 45 46 47 |
# File 'lib/probject/actor.rb', line 44 def async raise_if_terminated! Proxy.new(self, :async) end |
#future ⇒ Object Also known as: ask
asynchronous call returns Probject::Future
52 53 54 55 |
# File 'lib/probject/actor.rb', line 52 def future raise_if_terminated! Proxy.new(self, :future) end |
#pid ⇒ Object
18 19 20 |
# File 'lib/probject/actor.rb', line 18 def pid @____pid end |
#terminate(timeout = 10) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/probject/actor.rb', line 22 def terminate(timeout = 10) raise_if_terminated! @____terminated = true if timeout && timeout != 0 begin Timeout.timeout(timeout) do Actor.send_signal(@____pid, 'SIGTERM') end rescue Timeout::Error Actor.kill @____pid end else Actor.kill @____pid end end |
#terminated? ⇒ Boolean
38 39 40 |
# File 'lib/probject/actor.rb', line 38 def terminated? @____terminated end |