Class: Plumbing::Actor::Threaded
- Inherits:
-
Object
- Object
- Plumbing::Actor::Threaded
- Defined in:
- lib/plumbing/actor/threaded.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Message
Instance Method Summary collapse
- #in_context? ⇒ Boolean
-
#initialize(target) ⇒ Threaded
constructor
A new instance of Threaded.
- #safely ⇒ Object
-
#send_message(message_name, *args, **params, &block) ⇒ Object
Send the message to the target and wrap the result.
- #stop ⇒ Object
Constructor Details
#initialize(target) ⇒ Threaded
Returns a new instance of Threaded.
11 12 13 14 15 |
# File 'lib/plumbing/actor/threaded.rb', line 11 def initialize target @target = target @queue = Concurrent::Array.new @mutex = Thread::Mutex.new end |
Instance Method Details
#in_context? ⇒ Boolean
32 |
# File 'lib/plumbing/actor/threaded.rb', line 32 def in_context? = @mutex.owned? |
#safely ⇒ Object
26 27 28 29 30 |
# File 'lib/plumbing/actor/threaded.rb', line 26 def safely(&) Plumbing.config.logger.debug { "-> #{@target.class}#perform_safely\n#{Thread.current.name}" } (:perform_safely, &) nil end |
#send_message(message_name, *args, **params, &block) ⇒ Object
Send the message to the target and wrap the result
18 19 20 21 22 23 24 |
# File 'lib/plumbing/actor/threaded.rb', line 18 def (, *args, **params, &block) Plumbing.config.logger.debug { "-> #{@target.class}##{}(#{args.inspect}, #{params.inspect})\n#{Thread.current.name}" } Message.new(@target, , Plumbing::Actor.transporter.marshal(*args), Plumbing::Actor.transporter.marshal(params).first, block, Concurrent::MVar.new).tap do || @queue << end end |
#stop ⇒ Object
34 |
# File 'lib/plumbing/actor/threaded.rb', line 34 def stop = @queue.clear |