Class: Gamelan::Queue
- Inherits:
-
Object
- Object
- Gamelan::Queue
- Includes:
- Java
- Defined in:
- lib/gamelan/queue.rb,
lib/gamelan/queue.rb
Instance Method Summary collapse
-
#initialize(sched) ⇒ Queue
constructor
A new instance of Queue.
- #pop ⇒ Object
- #push(task) ⇒ Object (also: #<<)
- #ready? ⇒ Boolean
Constructor Details
#initialize(sched) ⇒ Queue
Returns a new instance of Queue.
9 10 11 12 13 14 |
# File 'lib/gamelan/queue.rb', line 9 def initialize(sched) @scheduler = sched comparator = lambda { |a,b| a.delay <=> b.delay } @queue = PriorityBlockingQueue.new(10000, &comparator) @lock = Mutex.new end |
Instance Method Details
#pop ⇒ Object
21 22 23 |
# File 'lib/gamelan/queue.rb', line 21 def pop @lock.synchronize { @queue.remove } end |
#push(task) ⇒ Object Also known as: <<
16 17 18 |
# File 'lib/gamelan/queue.rb', line 16 def push(task) @lock.synchronize { @queue.add(task) } end |
#ready? ⇒ Boolean
25 26 27 |
# File 'lib/gamelan/queue.rb', line 25 def ready? @queue.peek && @queue.peek.delay < @scheduler.phase end |