Class: FocusActor::AsyncProcessor
- Inherits:
-
Object
- Object
- FocusActor::AsyncProcessor
- Defined in:
- lib/focus_actor/async_processor.rb
Overview
This is a Proxy for instance. It can response instance methods on instance.
Start a new thread, and then loop to call methods in mailbox.
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#mailbox ⇒ Object
readonly
Returns the value of attribute mailbox.
Instance Method Summary collapse
-
#initialize(instance, mailbox: Queue.new) ⇒ AsyncProcessor
constructor
mailbox should be thread safe.
-
#method_missing(method, *args, &block) ⇒ Object
To call a method, push it to mailbox.
- #respond_to_missing?(method, include_all = false) ⇒ Boolean
Constructor Details
#initialize(instance, mailbox: Queue.new) ⇒ AsyncProcessor
mailbox should be thread safe
12 13 14 15 16 17 |
# File 'lib/focus_actor/async_processor.rb', line 12 def initialize(instance, mailbox: Queue.new) @instance = instance @mailbox = mailbox run! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
To call a method, push it to mailbox.
20 21 22 23 24 25 |
# File 'lib/focus_actor/async_processor.rb', line 20 def method_missing(method, *args, &block) return super unless instance.respond_to?(method) mailbox.push CellContext.new(method, args, block) nil end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
9 10 11 |
# File 'lib/focus_actor/async_processor.rb', line 9 def instance @instance end |
#mailbox ⇒ Object (readonly)
Returns the value of attribute mailbox.
9 10 11 |
# File 'lib/focus_actor/async_processor.rb', line 9 def mailbox @mailbox end |
Instance Method Details
#respond_to_missing?(method, include_all = false) ⇒ Boolean
27 28 29 |
# File 'lib/focus_actor/async_processor.rb', line 27 def respond_to_missing?(method, include_all = false) instance.respond_to?(method) || super end |