Module: Plumbing::Actor
- Extended by:
- Configuration
- Included in:
- Operation, Pipeline::Base, Provider
- Defined in:
- lib/plumbing/actor.rb,
lib/plumbing/actor/async.rb,
lib/plumbing/actor/rails.rb,
lib/plumbing/actor/inline.rb,
lib/plumbing/actor/worker.rb,
lib/plumbing/actor/message.rb,
lib/plumbing/actor/deferral.rb,
lib/plumbing/actor/threaded.rb,
lib/plumbing/actor/definitions.rb,
lib/plumbing/actor/configuration.rb
Defined Under Namespace
Modules: Configuration, Definitions Classes: Async, Deferral, Inline, Message, Rails, Threaded, Worker
Constant Summary collapse
- FIBER_KEY =
:plumbing_actor_sender_stack- NotSupported =
Raised when an actor asks for a capability its worker cannot provide (e.g. deferring a message on the inline worker).
Class.new(StandardError)
Instance Attribute Summary collapse
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Class Method Summary collapse
Instance Method Summary collapse
-
#after(delay, call:, sender: nil, **params, &block) ⇒ Object
Ask the worker to deliver
callto this actor afterdelayseconds. -
#cancel_deferred(deferral) ⇒ Object
Cancel a deferral returned by #after.
-
#current_sender ⇒ Object
The actor that sent the message currently being processed (the top of the sender stack), or nil.
-
#current_senders ⇒ Object
The full synchronous sender chain, outermost first.
- #initialize ⇒ Object
Methods included from Configuration
register, selected_worker_type, uses, worker_for, worker_types, workers
Instance Attribute Details
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
21 22 23 |
# File 'lib/plumbing/actor.rb', line 21 def worker @worker end |
Class Method Details
.included(klass) ⇒ Object
43 44 45 |
# File 'lib/plumbing/actor.rb', line 43 def self.included klass klass.extend Definitions end |
Instance Method Details
#after(delay, call:, sender: nil, **params, &block) ⇒ Object
Ask the worker to deliver call to this actor after delay seconds.
Returns a Plumbing::Actor::Deferral that can be passed to cancel_deferred.
36 37 38 |
# File 'lib/plumbing/actor.rb', line 36 def after(delay, call:, sender: nil, **params, &block) worker.after(delay, method: call, sender: sender, params: params, block: block) end |
#cancel_deferred(deferral) ⇒ Object
Cancel a deferral returned by #after.
41 |
# File 'lib/plumbing/actor.rb', line 41 def cancel_deferred(deferral) = worker.cancel_deferred(deferral) |
#current_sender ⇒ Object
The actor that sent the message currently being processed (the top of the sender stack), or nil. Set per-message by Message#deliver via a fiber-local stack — safe under the Async worker because each delivery runs in its own Async::Task fiber.
27 |
# File 'lib/plumbing/actor.rb', line 27 def current_sender = (Fiber[FIBER_KEY] || []).last |
#current_senders ⇒ Object
The full synchronous sender chain, outermost first. Under the inline worker this is the complete nested call-chain; under async each hop runs in its own fiber, so it holds the immediate sender only.
32 |
# File 'lib/plumbing/actor.rb', line 32 def current_senders = (Fiber[FIBER_KEY] || []).dup |
#initialize ⇒ Object
17 18 19 20 |
# File 'lib/plumbing/actor.rb', line 17 def initialize(...) super @worker = Plumbing::Actor.worker_for self end |