class ThreadSender
Public Class Methods
new()
click to toggle source
# File lib/ffi-tk/thread_sender.rb, line 3 def initialize @queue = Queue.new @thread = Thread.new{ reaper } end
Public Instance Methods
reaper()
click to toggle source
# File lib/ffi-tk/thread_sender.rb, line 8 def reaper loop do block, response_queue = *@queue.pop response_queue.push(block.call) end end
thread_send() { || ... }
click to toggle source
If callbacks are invoked within a thread_send
, we process them inside the same thread. Calling pop on the queue would cause deadlocks.
# File lib/ffi-tk/thread_sender.rb, line 18 def thread_send if @thread == Thread.current yield else response_queue = Queue.new @queue.push([Proc.new, response_queue]) response_queue.pop end end