Class: Taski::Execution::Registry
- Inherits:
-
Object
- Object
- Taski::Execution::Registry
- Defined in:
- lib/taski/execution/registry.rb
Instance Method Summary collapse
-
#abort_requested? ⇒ Boolean
True if abort has been requested.
-
#get_or_create(task_class) { ... } ⇒ Object
The task instance.
-
#get_task(task_class) ⇒ Object
The task instance.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register_thread(thread) ⇒ Object
- #request_abort! ⇒ Object
- #reset! ⇒ Object
-
#run(task_class, exported_methods) ⇒ Object
The result of the task execution.
- #wait_all ⇒ Object
Constructor Details
#initialize ⇒ Registry
8 9 10 11 12 13 |
# File 'lib/taski/execution/registry.rb', line 8 def initialize @tasks = {} @threads = [] @monitor = Monitor.new @abort_requested = false end |
Instance Method Details
#abort_requested? ⇒ Boolean
54 55 56 |
# File 'lib/taski/execution/registry.rb', line 54 def abort_requested? @monitor.synchronize { @abort_requested } end |
#get_or_create(task_class) { ... } ⇒ Object
Returns The task instance.
18 19 20 |
# File 'lib/taski/execution/registry.rb', line 18 def get_or_create(task_class) @tasks[task_class] ||= yield end |
#get_task(task_class) ⇒ Object
Returns The task instance.
25 26 27 28 29 |
# File 'lib/taski/execution/registry.rb', line 25 def get_task(task_class) @tasks.fetch(task_class) do raise "Task #{task_class} not registered" end end |
#register_thread(thread) ⇒ Object
32 33 34 |
# File 'lib/taski/execution/registry.rb', line 32 def register_thread(thread) @monitor.synchronize { @threads << thread } end |
#request_abort! ⇒ Object
49 50 51 |
# File 'lib/taski/execution/registry.rb', line 49 def request_abort! @monitor.synchronize { @abort_requested = true } end |
#reset! ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/taski/execution/registry.rb', line 41 def reset! @monitor.synchronize do @tasks.clear @threads.clear @abort_requested = false end end |
#run(task_class, exported_methods) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/taski/execution/registry.rb', line 61 def run(task_class, exported_methods) exported_methods.each do |method| task_class.public_send(method) end wait_all get_task(task_class).result end |
#wait_all ⇒ Object
36 37 38 39 |
# File 'lib/taski/execution/registry.rb', line 36 def wait_all threads = @monitor.synchronize { @threads.dup } threads.each(&:join) end |