Parent

Termtter::TaskManager

Public Class Methods

new(interval = 1) click to toggle source
# File lib/termtter/task_manager.rb, line 5
def initialize(interval = 1)
  @interval = interval
  @tasks = {}
  @work = true
  @mutex = Mutex.new
  @pause = false
end

Public Instance Methods

add_task(args = {}, &block) click to toggle source
# File lib/termtter/task_manager.rb, line 54
def add_task(args = {}, &block)
  synchronize do
    task = Task.new(args, &block)
    @tasks[task.name || task.object_id] = task
  end
end
delete_task(key) click to toggle source
# File lib/termtter/task_manager.rb, line 67
def delete_task(key)
  synchronize do
    @tasks.delete(key)
  end
end
get_task(key) click to toggle source
# File lib/termtter/task_manager.rb, line 61
def get_task(key)
  synchronize do
    @tasks[key]
  end
end
invoke_and_wait(&block) click to toggle source
# File lib/termtter/task_manager.rb, line 48
def invoke_and_wait(&block)
  synchronize do
    yield
  end
end
invoke_later() click to toggle source
# File lib/termtter/task_manager.rb, line 42
def invoke_later
  Thread.new do
    invoke_and_wait { yield }
  end
end
kill() click to toggle source
# File lib/termtter/task_manager.rb, line 21
def kill
  @work = false
end
pause() click to toggle source
# File lib/termtter/task_manager.rb, line 13
def pause
  @pause = true
end
resume() click to toggle source
# File lib/termtter/task_manager.rb, line 17
def resume
  @pause = false
end
run() click to toggle source
# File lib/termtter/task_manager.rb, line 25
def run
  Thread.new do
    while @work
      step unless @pause
      sleep @interval
    end
  end
end
step() click to toggle source
# File lib/termtter/task_manager.rb, line 34
def step
  pull_due_tasks.each do |task|
    invoke_and_wait do
      task.execute
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.