Skip to content

Commit 7ddc47f

Browse files
authored
Better error handling in async_map. (#10)
1 parent 89fb740 commit 7ddc47f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/async/await/enumerable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def async_map(parent: nil, &block)
1313
parent ||= task
1414

1515
self.map do |*arguments|
16-
parent.async do
16+
parent.async(finished: false) do
1717
yield(*arguments)
1818
end
1919
end.map(&:wait)

test/async/await/enumerable.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
expect(result).to be == [2, 4, 6]
1616
end
17+
18+
it "should fail if the block fails" do
19+
expect do
20+
[1, 2, 3].async_map do |value|
21+
raise "Fake error!"
22+
end
23+
end.to raise_exception(RuntimeError, message: be == "Fake error!")
24+
end
1725
end
1826

1927
with '#async_each' do

0 commit comments

Comments
 (0)