Class: ActiveRecord::ConnectionAdapters::FiberedMonitor::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/fiber_patches.rb

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.



15
16
17
# File 'lib/active_record/fiber_patches.rb', line 15

def initialize
  @queue = []
end

Instance Method Details

#signalObject



32
33
34
35
# File 'lib/active_record/fiber_patches.rb', line 32

def signal
  fiber = @queue.pop
  fiber.resume(true) if fiber
end

#wait(timeout) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/fiber_patches.rb', line 19

def wait(timeout)
  t = timeout || 5
  fiber = Fiber.current
  x = EM::Timer.new(t) do
    @queue.delete(fiber)
    fiber.resume(false)
  end
  @queue << fiber
  returning Fiber.yield do
    x.cancel
  end
end