diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2015-06-05 22:50:30 +0200 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2015-06-05 22:51:24 +0200 |
commit | 6f380e80d6e4c64b5c0965e6a288deb55442b5d3 (patch) | |
tree | d1eed4dde0d7d7054fd3b3c78b83c0ccc3036418 /lib/elixir/test/elixir/stream_test.exs | |
parent | a52bf5f40e6d5c60f1e8dbf86a07c0ef08b03219 (diff) | |
download | elixir-6f380e80d6e4c64b5c0965e6a288deb55442b5d3.tar.gz |
Only consider outer halts in flat_map when the op is not halt itself
Diffstat (limited to 'lib/elixir/test/elixir/stream_test.exs')
-rw-r--r-- | lib/elixir/test/elixir/stream_test.exs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/elixir/test/elixir/stream_test.exs b/lib/elixir/test/elixir/stream_test.exs index dc7ac1ce8..966a5fffa 100644 --- a/lib/elixir/test/elixir/stream_test.exs +++ b/lib/elixir/test/elixir/stream_test.exs @@ -342,6 +342,18 @@ defmodule StreamTest do assert Enum.take(stream, 5) == [1, 2, 3, 4, 3] end + test "flat_map/2 properly halts both inner and outer stream when inner stream is halted" do + # Fixes a bug that, when the inner stream was done, + # sending it a halt would cause it to return the + # inner stream was halted, forcing flat_map to get + # the next value from the outer stream, evaluate it, + # get annother inner stream, just to halt it. + assert [1, 2] # 2 should never be used + |> Stream.flat_map(fn 1 -> Stream.repeatedly(fn -> 1 end) end) + |> Stream.flat_map(fn 1 -> Stream.repeatedly(fn -> 1 end) end) + |> Enum.take(1) == [1] + end + test "interval/1" do stream = Stream.interval(10) now = :os.timestamp |