Class: Framed::Emitters::Threaded
Instance Method Summary collapse
- #enqueue(event) ⇒ Object
-
#initialize(client) ⇒ Threaded
constructor
A new instance of Threaded.
- #start ⇒ Object
- #stop(drain = false) ⇒ Object
Constructor Details
#initialize(client) ⇒ Threaded
Returns a new instance of Threaded.
53 54 55 56 |
# File 'lib/framed/emitters.rb', line 53 def initialize(client) super @queue = Queue.new end |
Instance Method Details
#enqueue(event) ⇒ Object
58 59 60 61 |
# File 'lib/framed/emitters.rb', line 58 def enqueue(event) @queue << event start end |
#start ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/framed/emitters.rb', line 63 def start return if @thread @thread = Thread.new do while true begin process_events rescue StandardError => exc Framed.logger.error("framed_rails: run_thread failed: #{exc}") stop end sleep(0.5) end end end |
#stop(drain = false) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/framed/emitters.rb', line 79 def stop(drain = false) if @thread @thread.kill end @thread = nil if drain && @queue.length process_events end end |