-
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
127 additions
and
26 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
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,42 @@ | ||
defmodule Observables.CombineLatest do | ||
@moduledoc false | ||
use Observables.GenObservable | ||
|
||
def init([]) do | ||
Logger.debug("CombineLatest: #{inspect(self())}") | ||
{:ok, {:left, nil, :right, nil}} | ||
end | ||
|
||
def handle_event(value, state) do | ||
case {value, state} do | ||
# No values at all, and got a left. | ||
{{:left, vl}, {:left, nil, :right, nil}} -> | ||
{:novalue, {:left, vl, :right, nil}} | ||
|
||
# No values yet, and got a right. | ||
{{:right, vr}, {:left, nil, :right, nil}} -> | ||
{:novalue, {:left, nil, :right, vr}} | ||
|
||
# Already have left, now got right. | ||
{{:right, vr}, {:left, vl, :right, nil}} -> | ||
{:value, {vl, vr}, {:left, nil, :right, nil}} | ||
|
||
# Already have a left, and received a left. | ||
{{:left, vl}, {:left, _vl, :right, nil}} -> | ||
{:novalue, {:left, vl, :right, nil}} | ||
|
||
# Already have a right value, and now received left. | ||
{{:left, vl}, {:left, nil, :right, vr}} -> | ||
{:value, {vl, vr}, {:left, nil, :right, nil}} | ||
|
||
# Already have a right, and received a right. | ||
{{:right, vr}, {:left, nil, :right, _vr}} -> | ||
{:novalue, {:left, nil, :right, vr}} | ||
end | ||
end | ||
|
||
def handle_done(_pid, _state) do | ||
Logger.debug("#{inspect(self())}: zip has one dead dependency, stopping.") | ||
{:ok, :done} | ||
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