Class: Chingu::Async::TaskList

Inherits:
Object
  • Object
show all
Defined in:
lib/chingu/async/task_list.rb

Instance Method Summary collapse

Constructor Details

#initializeTaskList

extend Forwardable def_delegator :@queue, :push, :enq def_delegator :@queue, :shift, :deq def_delegator :@queue, :first, :front def_delegator :@queue, :clear



32
33
34
# File 'lib/chingu/async/task_list.rb', line 32

def initialize
  @queue = []
end

Instance Method Details

#clearObject



60
61
62
# File 'lib/chingu/async/task_list.rb', line 60

def clear
  @queue.clear
end

#deqObject



56
57
58
# File 'lib/chingu/async/task_list.rb', line 56

def deq
  @queue.shift
end

#enq(*tasks) ⇒ Object



52
53
54
# File 'lib/chingu/async/task_list.rb', line 52

def enq(*tasks)
  @queue.push(*tasks)
end

#frontObject



48
49
50
# File 'lib/chingu/async/task_list.rb', line 48

def front
  @queue.first
end

#update(object) ⇒ Object

Processes the first task on the queue, each tick removing the task once it has finished.



40
41
42
43
44
45
46
# File 'lib/chingu/async/task_list.rb', line 40

def update(object)
  if task = front
    task.update object
    deq if task.finished?
    task
  end
end