Skip to content

Commit 53a67a1

Browse files
tgwizarderegon
authored andcommitted
Use executor from arg in then_on/rescue_on/chain_on for Promises
1 parent 25ccddc commit 53a67a1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

lib/concurrent-ruby/concurrent/promises.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def chain(*args, &task)
611611
# @yieldparam [Object] value
612612
# @yieldparam [Object] reason
613613
def chain_on(executor, *args, &task)
614-
ChainPromise.new_blocked_by1(self, @DefaultExecutor, executor, args, &task).future
614+
ChainPromise.new_blocked_by1(self, executor, executor, args, &task).future
615615
end
616616

617617
# @return [String] Short string representation.
@@ -1034,7 +1034,7 @@ def then(*args, &task)
10341034
# @return [Future]
10351035
# @yield [value, *args] to the task.
10361036
def then_on(executor, *args, &task)
1037-
ThenPromise.new_blocked_by1(self, @DefaultExecutor, executor, args, &task).future
1037+
ThenPromise.new_blocked_by1(self, executor, executor, args, &task).future
10381038
end
10391039

10401040
# @!macro promises.shortcut.on
@@ -1052,7 +1052,7 @@ def rescue(*args, &task)
10521052
# @return [Future]
10531053
# @yield [reason, *args] to the task.
10541054
def rescue_on(executor, *args, &task)
1055-
RescuePromise.new_blocked_by1(self, @DefaultExecutor, executor, args, &task).future
1055+
RescuePromise.new_blocked_by1(self, executor, executor, args, &task).future
10561056
end
10571057

10581058
# @!macro promises.method.zip

spec/concurrent/promises_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,12 @@ def behaves_as_delay(delay, value)
380380
end
381381

382382
it 'chains' do
383-
future0 = future { 1 }.then { |v| v + 2 } # both executed on default FAST_EXECUTOR
384-
future1 = future0.then_on(:fast) { raise 'boo' } # executed on IO_EXECUTOR
385-
future2 = future1.then { |v| v + 1 } # will reject with 'boo' error, executed on default FAST_EXECUTOR
386-
future3 = future1.rescue { |err| err.message } # executed on default FAST_EXECUTOR
387-
future4 = future0.chain { |success, value, reason| success } # executed on default FAST_EXECUTOR
388-
future5 = future3.with_default_executor(:fast) # connects new future with different executor, the new future is resolved when future3 is
383+
future0 = future { 1 }.then { |v| v + 2 } # both executed on default IO_EXECUTOR
384+
future1 = future0.then_on(:fast) { raise 'boo' } # executed on FAST_EXECUTOR
385+
future2 = future1.then { |v| v + 1 } # will reject with 'boo' error, executed on FAST_EXECUTOR
386+
future3 = future1.rescue { |err| err.message } # executed on FAST_EXECUTOR
387+
future4 = future0.chain { |success, value, reason| success } # executed on FAST_EXECUTOR
388+
future5 = future3.with_default_executor(:io) # connects new future with different executor, the new future is resolved when future3 is
389389
future6 = future5.then(&:capitalize) # executes on IO_EXECUTOR because default was set to :io on future5
390390
future7 = future0 & future3
391391
future8 = future0.rescue { raise 'never happens' } # future0 fulfills so future8'll have same value as future 0
@@ -402,12 +402,12 @@ def behaves_as_delay(delay, value)
402402
expect(table.join("\n")).to eq <<-TABLE.gsub(/^\s+\|/, '').strip
403403
|index success value reason pool d.pool
404404
| 0 true 3 io io
405-
| 1 false boo fast io
406-
| 2 false boo io io
407-
| 3 true boo io io
405+
| 1 false boo fast fast
406+
| 2 false boo fast fast
407+
| 3 true boo fast fast
408408
| 4 true true io io
409-
| 5 true boo fast
410-
| 6 true Boo fast fast
409+
| 5 true boo io
410+
| 6 true Boo io io
411411
| 7 true [3, "boo"] io
412412
| 8 true 3 io io
413413
TABLE

0 commit comments

Comments
 (0)