Class: Gamelan::Queue

Inherits:
Object
  • Object
show all
Includes:
Java
Defined in:
lib/gamelan/queue.rb,
lib/gamelan/queue.rb

Instance Method Summary collapse

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

#popObject



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

Returns:

  • (Boolean)


25
26
27
# File 'lib/gamelan/queue.rb', line 25

def ready?
  @queue.peek && @queue.peek.delay < @scheduler.phase
end