Class: Rust::Jobs::Task
Instance Method Summary collapse
- #commit ⇒ Object
-
#initialize(title, &block) ⇒ Task
constructor
A new instance of Task.
- #notify ⇒ Object
- #on_complete(&block) ⇒ Object
- #on_error(&block) ⇒ Object
- #start ⇒ Object
- #waitfor(granularity = 0.1) ⇒ Object
Constructor Details
#initialize(title, &block) ⇒ Task
Returns a new instance of Task.
23 24 25 26 27 28 29 30 31 |
# File 'lib/rust/jobs/jobs.rb', line 23 def initialize(title, &block) raise "Expected block to describe the task" unless block_given? @title = title @todo = block @done = false @complete_hook = proc {} @error_hook = proc {} end |
Instance Method Details
#commit ⇒ Object
49 50 |
# File 'lib/rust/jobs/jobs.rb', line 49 def commit end |
#notify ⇒ Object
39 40 41 |
# File 'lib/rust/jobs/jobs.rb', line 39 def notify @done = true end |
#on_complete(&block) ⇒ Object
52 53 54 55 |
# File 'lib/rust/jobs/jobs.rb', line 52 def on_complete(&block) raise "Block expected" unless block_given? @complete_hook = block end |
#on_error(&block) ⇒ Object
57 58 59 60 |
# File 'lib/rust/jobs/jobs.rb', line 57 def on_error(&block) raise "Block expected" unless block_given? @error_hook = block end |
#start ⇒ Object
33 34 35 36 37 |
# File 'lib/rust/jobs/jobs.rb', line 33 def start @thread = Thread.start do @todo.call(TaskHook.new(@complete_hook, @error_hook)) end end |
#waitfor(granularity = 0.1) ⇒ Object
43 44 45 46 47 |
# File 'lib/rust/jobs/jobs.rb', line 43 def waitfor(granularity=0.1) while !@done sleep granularity end end |