Class: Plumbing::Actor::Message

Inherits:
Literal::Object
  • Object
show all
Includes:
Plumbing::Awaitable
Defined in:
lib/plumbing/actor/message.rb

Direct Known Subclasses

Inline::Message

Instance Method Summary collapse

Instance Method Details

#_wait_until_readyObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/plumbing/actor/message.rb', line 38

def _wait_until_ready
  raise NotImplementedError
end

#awaitObject



33
34
35
36
# File 'lib/plumbing/actor/message.rb', line 33

def await
  _wait_until_ready
  @exception.nil? ? @result : raise(@exception)
end

#deliverObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/plumbing/actor/message.rb', line 18

def deliver
  stack = (Fiber[Plumbing::Actor::FIBER_KEY] ||= [])
  stack.push(@sender)
  @result = @actor.send(@implementation, **@params, &@block)
  @status = :done
rescue => ex
  @exception = ex
  @status = :error
ensure
  stack.pop
  # Keep the "nil at the top level" invariant: once the outermost message
  # unwinds, clear the fiber-local rather than leaving an empty array.
  Fiber[Plumbing::Actor::FIBER_KEY] = nil if stack.empty?
end