Last active
August 29, 2015 14:16
-
-
Save elbow-jason/a81b51370822b62a0d5a to your computer and use it in GitHub Desktop.
Stream is causing iex to hang for some reason...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule LoggerHandler do | |
use GenEvent | |
# Callbacks | |
def handle_event({:log, x}, messages) do | |
{:ok, [x|messages]} | |
end | |
def handle_call(:messages, messages) do | |
{:ok, Enum.reverse(messages), []} | |
end | |
end | |
{:ok, pid} = GenEvent.start_link() | |
GenEvent.add_handler(pid, LoggerHandler, []) | |
GenEvent.notify(pid, {:log, 1}) | |
GenEvent.notify(pid, {:log, 2}) | |
GenEvent.notify(pid, {:log, 3}) | |
# uncomment the following line and iex hangs indefinitely. | |
# pid |> GenEvent.stream |> Enum.take(1) # this hangs inside iex | |
pid |> GenEvent.stream(timeout: 500) |> Enum.take(1) # this times out after half a second |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works.
Jose Valim has my thanks for his help in this solution.