class DepthFirst::ParallelOrganizer
Base parallel organizer class
Constants
- DEPENDENCIES
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/depth_first/parallel_organizer.rb, line 6 def initialize(options) super(options) load_dependencies end
Public Instance Methods
perform()
click to toggle source
# File lib/depth_first/parallel_organizer.rb, line 11 def perform tasks.map { |task| execute_promise(task) } .reduce(options) { |a, e| resolve_promise(a, e) } end
Private Instance Methods
dependencies()
click to toggle source
# File lib/depth_first/parallel_organizer.rb, line 24 def dependencies self.class::DEPENDENCIES end
execute_promise(task)
click to toggle source
# File lib/depth_first/parallel_organizer.rb, line 28 def execute_promise(task) Concurrent::Promise.new { task.new(options).perform }.execute end
load_dependencies()
click to toggle source
Load dependencies before concurrency to get around lazy-loading race condition.
# File lib/depth_first/parallel_organizer.rb, line 20 def load_dependencies dependencies.each { |dependency| dependency } end
resolve_promise(hsh, result)
click to toggle source
# File lib/depth_first/parallel_organizer.rb, line 32 def resolve_promise(hsh, result) result.value ? hsh.merge(result.value) : (raise result.reason) end