Class: Phronomy::Runtime::TaskRegistry Private
- Inherits:
-
Object
- Object
- Phronomy::Runtime::TaskRegistry
- Defined in:
- lib/phronomy/runtime/task_registry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal registry of active Task instances for a Phronomy::Runtime.
Tracks every task that has been spawned but not yet completed so that #shutdown can drain them. Tasks that complete synchronously (e.g. under FakeScheduler / ImmediateBackend) deregister themselves before the caller returns from #spawn, so they are never added to the registry in the first place.
Instance Method Summary collapse
-
#deregister(task) ⇒ void
private
Removes +task+ from the registry (called from the task's ensure block).
-
#drain ⇒ void
private
Waits for all registered tasks to finish (used by #shutdown).
-
#initialize ⇒ TaskRegistry
constructor
private
A new instance of TaskRegistry.
-
#register(task) ⇒ void
private
Adds +task+ to the registry unless it already completed synchronously.
Constructor Details
#initialize ⇒ TaskRegistry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TaskRegistry.
14 15 16 17 |
# File 'lib/phronomy/runtime/task_registry.rb', line 14 def initialize @mutex = Mutex.new @tasks = [] end |
Instance Method Details
#deregister(task) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Removes +task+ from the registry (called from the task's ensure block).
31 32 33 |
# File 'lib/phronomy/runtime/task_registry.rb', line 31 def deregister(task) @mutex.synchronize { @tasks.delete(task) } end |
#drain ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Waits for all registered tasks to finish (used by Phronomy::Runtime#shutdown).
38 39 40 41 42 43 44 45 |
# File 'lib/phronomy/runtime/task_registry.rb', line 38 def drain tasks = @mutex.synchronize { @tasks.dup } tasks.each do |t| t.join rescue nil end end |
#register(task) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Adds +task+ to the registry unless it already completed synchronously.
23 24 25 |
# File 'lib/phronomy/runtime/task_registry.rb', line 23 def register(task) @mutex.synchronize { @tasks << task unless task.done? } end |