Class: Plumbing::Actor::Async
- Inherits:
-
Object
- Object
- Plumbing::Actor::Async
- Defined in:
- lib/plumbing/actor/async.rb
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #in_context? ⇒ Boolean
-
#initialize(target) ⇒ Async
constructor
A new instance of Async.
- #safely ⇒ Object
-
#send_message(message_name, *args, **params, &block) ⇒ Object
Send the message to the target and wrap the result.
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/plumbing/actor/async.rb', line 8 def target @target end |
Instance Method Details
#in_context? ⇒ Boolean
33 |
# File 'lib/plumbing/actor/async.rb', line 33 def in_context? = true |
#safely ⇒ Object
26 27 28 29 30 31 |
# File 'lib/plumbing/actor/async.rb', line 26 def safely(&) Plumbing.config.logger.debug { "-> #{@target.class}#perform_safely" } (:perform_safely, &) sleep 0.01 nil end |
#send_message(message_name, *args, **params, &block) ⇒ Object
Send the message to the target and wrap the result
16 17 18 19 20 21 22 23 24 |
# File 'lib/plumbing/actor/async.rb', line 16 def (, *args, **params, &block) Plumbing.config.logger.debug { "-> #{@target.class}##{}(#{args.inspect}, #{params.inspect})" } task = @semaphore.async do Plumbing.config.logger.debug { "---> #{@target.class}##{}(#{args.inspect}, #{params.inspect})" } @target.send(, *args, **params, &block) end sleep 0.01 Result.new(task) end |
#stop ⇒ Object
35 |
# File 'lib/plumbing/actor/async.rb', line 35 def stop = nil |