Skip to content

Commit 85b99b5

Browse files
committed
Add flat aliases
1 parent 8596155 commit 85b99b5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib-edge/concurrent/edge/promises.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ def then_ask(actor)
1616
end
1717

1818
include ActorIntegration
19+
20+
# @!macro warn.edge
21+
module FlatShortcuts
22+
23+
def then_flat_future(*args, &block)
24+
self.then(*args, &block).flat_future
25+
end
26+
27+
alias_method :then_flat, :then_flat_future
28+
29+
def then_flat_future_on(executor, *args, &block)
30+
self.then_on(executor, *args, &block).flat_future
31+
end
32+
33+
alias_method :then_flat_on, :then_flat_future_on
34+
35+
def then_flat_event(*args, &block)
36+
self.then(*args, &block).flat_event
37+
end
38+
39+
def then_flat_event_on(executor, *args, &block)
40+
self.then_on(executor, *args, &block).flat_event
41+
end
42+
end
43+
44+
include FlatShortcuts
1945
end
2046

2147
class Channel < Concurrent::Synchronization::Object

spec/concurrent/edge/promises_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ def behaves_as_delay(delay, value)
445445
expect(::Array.new(3) { |i| Concurrent::Promises.delay { i } }.
446446
inject { |a, b| a.then { b }.flat }.value!(0.2)).to eq 2
447447
end
448+
449+
it 'has shortcuts' do
450+
expect(fulfilled_future(1).then_flat { |v| future(v) { v + 1 } }.value!).to eq 2
451+
expect(fulfilled_future(1).then_flat_event { |v| resolved_event }.wait.resolved?).to eq true
452+
expect(fulfilled_future(1).then_flat_on(:fast) { |v| future(v) { v + 1 } }.value!).to eq 2
453+
end
448454
end
449455

450456
it 'resolves future when Exception raised' do

0 commit comments

Comments
 (0)