Class: Rbgo::TaskList
- Inherits:
-
Object
- Object
- Rbgo::TaskList
- Defined in:
- lib/rbgo/task_list.rb
Instance Attribute Summary collapse
-
#last_error ⇒ Object
Returns the value of attribute last_error.
Instance Method Summary collapse
- #<<(task) ⇒ Object
- #add(task, timeout: nil, skip_on_exception: false) ⇒ Object
- #clear_task ⇒ Object
- #complete? ⇒ Boolean
- #running? ⇒ Boolean
- #start(arg = nil) ⇒ Object
- #wait(timeout = nil) ⇒ Object
- #wakeup ⇒ Object
Instance Attribute Details
#last_error ⇒ Object
Returns the value of attribute last_error.
8 9 10 |
# File 'lib/rbgo/task_list.rb', line 8 def last_error @last_error end |
Instance Method Details
#<<(task) ⇒ Object
10 11 12 13 |
# File 'lib/rbgo/task_list.rb', line 10 def <<(task) task_queue << task self end |
#add(task, timeout: nil, skip_on_exception: false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbgo/task_list.rb', line 15 def add(task, timeout: nil, skip_on_exception: false) task_queue << proc do |last_task_result| begin Timeout::timeout(timeout) do task.call(last_task_result) end rescue Exception => ex self.last_error = ex raise unless skip_on_exception end end self end |
#clear_task ⇒ Object
36 37 38 |
# File 'lib/rbgo/task_list.rb', line 36 def clear_task task_queue.clear end |
#complete? ⇒ Boolean
44 45 46 |
# File 'lib/rbgo/task_list.rb', line 44 def complete? !running? && task_queue.empty? end |
#running? ⇒ Boolean
40 41 42 |
# File 'lib/rbgo/task_list.rb', line 40 def running? running end |
#start(arg = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rbgo/task_list.rb', line 29 def start(arg = nil) start_once.do do _start(arg) end nil end |
#wait(timeout = nil) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/rbgo/task_list.rb', line 52 def wait(timeout = nil) wait_mutex.synchronize do if running? wait_cond.wait(wait_mutex, timeout) end end end |
#wakeup ⇒ Object
48 49 50 |
# File 'lib/rbgo/task_list.rb', line 48 def wakeup wait_cond.signal end |