From 6f380e80d6e4c64b5c0965e6a288deb55442b5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 5 Jun 2015 22:50:30 +0200 Subject: Only consider outer halts in flat_map when the op is not halt itself --- lib/elixir/test/elixir/stream_test.exs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/elixir/test/elixir/stream_test.exs') 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 -- cgit v1.2.1