Class: Swiftcore::Tasks::TaskList

Inherits:
SortedSet
  • Object
show all
Defined in:
lib/swiftcore/tasks/tasklist.rb

Overview

Just a SortedSet with a few special powers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TaskList

Returns a new instance of TaskList.



12
13
14
15
# File 'lib/swiftcore/tasks/tasklist.rb', line 12

def initialize(*args)
  @status = :pending
  super(*args)
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



10
11
12
# File 'lib/swiftcore/tasks/tasklist.rb', line 10

def status
  @status
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/swiftcore/tasks/tasklist.rb', line 23

def finished?
  @status = :finished if empty?
  @status == :finished
end

#runObject



17
18
19
20
21
# File 'lib/swiftcore/tasks/tasklist.rb', line 17

def run
  @status = :running
  tick while any?
  @status = :finished
end

#tickObject

Run a single task in the queue.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/swiftcore/tasks/tasklist.rb', line 29

def tick
  prior_status = @status
  @status = :tick
  task = first
  result = task.call
  delete task
  merge(result) if result.is_a?(TaskList)
  @status = prior_status
  finished?
  result
end