Skip to content

Commit e75a675

Browse files
author
José Valim
committed
Add missing after callback in Stream.transform
1 parent 77e6022 commit e75a675

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/elixir/lib/stream.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ defmodule Stream do
696696
kind, reason ->
697697
stacktrace = System.stacktrace
698698
next.({:halt, next_acc})
699+
do_after(after_fun, user_acc)
699700
:erlang.raise(kind, reason, stacktrace)
700701
else
701702
{[], user_acc} ->

lib/elixir/test/elixir/stream_test.exs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ defmodule StreamTest do
467467
assert r1 != r2
468468
end
469469

470-
test "resource/3 closes on errors" do
470+
test "resource/3 closes on outer errors" do
471471
stream = Stream.resource(fn -> 1 end,
472-
fn acc -> {[acc], acc + 1} end,
473-
fn _ -> Process.put(:stream_resource, true) end)
472+
fn 2 -> throw(:error)
473+
acc -> {[acc], acc + 1} end,
474+
fn 2 -> Process.put(:stream_resource, true) end)
474475

475476
Process.put(:stream_resource, false)
476-
stream = Stream.map(stream, fn x -> if x > 2, do: throw(:error), else: x end)
477477
assert catch_throw(Enum.to_list(stream)) == :error
478478
assert Process.get(:stream_resource)
479479
end
@@ -570,13 +570,13 @@ defmodule StreamTest do
570570
assert Process.get(:stream_transform)
571571
end
572572

573-
test "transform/4 closes on errors" do
573+
test "transform/4 closes on outer errors" do
574574
stream = Stream.transform(1..10, fn -> 0 end,
575-
fn x, acc -> {[x + acc], x} end,
575+
fn 3, _ -> throw(:error)
576+
x, acc -> {[x + acc], x} end,
576577
fn 2 -> Process.put(:stream_transform, true) end)
577578

578579
Process.put(:stream_transform, false)
579-
stream = Stream.map(stream, fn x -> if x > 2, do: throw(:error), else: x end)
580580
assert catch_throw(Enum.to_list(stream)) == :error
581581
assert Process.get(:stream_transform)
582582
end
@@ -640,7 +640,7 @@ defmodule StreamTest do
640640

641641
test "transform/4 closes on errors with inner enum" do
642642
stream = Stream.transform(1..10, fn -> :acc end,
643-
fn x, acc -> {[x..x+2], acc} end,
643+
fn x, acc -> {x..x+2, acc} end,
644644
fn :acc -> Process.put(:stream_transform, true) end)
645645

646646
Process.put(:stream_transform, false)
@@ -652,7 +652,7 @@ defmodule StreamTest do
652652
test "transform/4 is zippable with inner enum" do
653653
stream = Stream.transform(1..20, fn -> :inner end,
654654
fn 10, acc -> {:halt, acc}
655-
x, acc -> {[x..x+2], acc}
655+
x, acc -> {x..x+2, acc}
656656
end,
657657
fn :inner -> Process.put(:stream_transform, true) end)
658658

0 commit comments

Comments
 (0)