Class: Smith::Workflow::Parallel
- Inherits:
-
Object
- Object
- Smith::Workflow::Parallel
show all
- Defined in:
- lib/smith/workflow/parallel.rb
Defined Under Namespace
Classes: CancellationSignal
Class Method Summary
collapse
Class Method Details
.execute(branches:) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/smith/workflow/parallel.rb', line 27
def self.execute(branches:)
signal = CancellationSignal.new
futures = branches.map do |branch|
Concurrent::Promises.future(branch, signal) do |b, s|
b.call(s)
rescue StandardError
s.cancel!
raise
end
end
fulfilled, values, reasons = Concurrent::Promises.zip(*futures).result
unless fulfilled
error = reasons.compact.first
raise error
end
values
end
|
.resolve_branch_count(transition, context) ⇒ Object
22
23
24
25
|
# File 'lib/smith/workflow/parallel.rb', line 22
def self.resolve_branch_count(transition, context)
count = transition.agent_opts[:count]
count.respond_to?(:call) ? count.call(context) : (count || 1)
end
|