-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule Observables.Operator.Delay do | ||
@moduledoc false | ||
use Observables.GenObservable | ||
|
||
def init([delay]) do | ||
{:ok, %{:delay => delay}} | ||
end | ||
|
||
def handle_event(v, state = %{:delay => delay}) do | ||
Logger.warn "Got this: #{inspect v}" | ||
case v do | ||
{:delayed, x} -> | ||
{:value, x, state} | ||
v -> | ||
Process.send_after(self(), {:event, {:delayed, v}}, delay) | ||
{:novalue, state} | ||
end | ||
|
||
end | ||
|
||
def handle_done(pid, _state) do | ||
Logger.debug("#{inspect(self())}: dependency stopping: #{inspect(pid)}") | ||
{:ok, :continue} | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule DelayTest do | ||
use ExUnit.Case | ||
alias Observables.{Obs} | ||
require Logger | ||
|
||
@tag :delay | ||
test "delay" do | ||
Code.load_file("test/util.ex") | ||
testproc = self() | ||
|
||
# Create a range. | ||
Obs.range(1, 5, 100) | ||
|> Obs.delay(1000) | ||
|> Obs.each(fn v -> | ||
Logger.error "Got #{v}" | ||
send(testproc, v) | ||
end) | ||
|
||
# Receive no other values. | ||
# receive do | ||
# _x -> | ||
# Logger.error("Received another value, did not want") | ||
# assert "received another value:" == "" | ||
# after | ||
# 5000 -> | ||
# :ok | ||
# end | ||
|
||
# 1..5 | ||
# |> Enum.map(fn v -> | ||
# assert_receive(^v, 5000, "did not get this message #{v}") | ||
# end) | ||
Test.Util.sleep(100000) | ||
|
||
end | ||
end |
This file contains 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