class FocusActor::AsyncProcessor
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.
Attributes
instance[R]
mailbox[R]
Public Class Methods
new(instance, mailbox: Queue.new)
click to toggle source
mailbox should be thread safe
# File lib/focus_actor/async_processor.rb, line 12 def initialize(instance, mailbox: Queue.new) @instance = instance @mailbox = mailbox run! end
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
To call a method, push it to mailbox.
Calls superclass method
# 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
respond_to_missing?(method, include_all = false)
click to toggle source
Calls superclass method
# File lib/focus_actor/async_processor.rb, line 27 def respond_to_missing?(method, include_all = false) instance.respond_to?(method) || super end
Private Instance Methods
run!()
click to toggle source
# File lib/focus_actor/async_processor.rb, line 31 def run! Thread.new do loop do cell_context = mailbox.pop instance.public_send(cell_context.method, *cell_context.args, &cell_context.block) end end end