Reaxive.Rx.Impl
Implements the Rx protocols and handles the contract. This module is internally used
as the workhorse for most Rx combinators. However, any user should not rely on inner
workings but use only Reaxive.Rx.
, since this module is subject to change.
There are several issues with this implementation, in particular from an idiomatic point of view and it is too complicated.
Summary
compose(observable, arg) | Composes the internal action on received events with the given |
compose(observable, fun, acc) | |
disconnect_all(state) | Internal function to disconnect from the sources |
disconnect_source(state, src_id) | Internal function for disconnecting a single source. This function
does not change anything beyond the |
do_action(fun, event, accu, new_accu) | Internal function calculating the new value |
do_run(state) | run the sequence by calling |
do_subscribe(state, observer) | Internal function for subscribing a new |
emit(impl, event) | Either emits a value or puts it into the queue |
fun(observable, fun, acc \\ []) | This function sets the internal action on received events before the event is propagated to the subscribers. An initial accumulator value can also be provided |
get_sources(observable) | All sources of Rx. Useful for debugging |
handle_call(msg, from, state) | All request-reply calls for setting up the Rx |
handle_cast(msg, state) | Asynchronous callback. Used for processing values and subscription |
handle_event(state, event) | Internal function to handles the various events, in particular disconnects
the source which is sending a |
handle_value(state, value) | Internal function to handle new values, errors or completions. If |
notify(arg, state) | Internal function to notify subscribers, knows about ignoring notifies |
on_completed(observer, observable) | The last regular message |
on_error(observer, exception) | An error has occured, the pipeline will be aborted |
on_next(observer, value) | Process the next value |
on_run(observable, on_run) | Sets the on_run function, which is called for the first subscription |
run(observable) | Starts the event sequence |
set_auto_stop(observable, auto_stop) | Sets the auto_stop flag for the running Rx |
source(observable, disposable) | Sets the disposable event sequence |
start() | Starts the Rx Impl. If |
start(name, options) | |
subscribe(observable, observer) | Subscribes a new observer. Returns a function for unsubscribing the observer |
subscribers(observable) | All subscribers of Rx. Useful for debugging |
terminate(reason, arg2) | Internal callback function at termination for clearing resources |
terminate?(impl) | Internal predicate to check if we
|
terminate_if_required(state) | |
terminate_if_required(state, return) | |
unsubscribe(observable, observer) | Unsubscribes an |
Types
rx_propagate :: {:on_next, term} | {:on_error, term} | {:on_completed, nil | pid}
Internal message for propagating events.
reduce_tag :: :cont | :halt | :ignore
Tags for interacting between reduce-function and its reducers. They have the following implications:
:cont
: continue with the iteration and send the current value to subscribers:ignore
: continue the iteration, but do not set anything to subscribers (i.e. ignore the value):halt
: stop the iteration and send the current value to subscribers
reducer :: {reduce_tag, rx_propagate, term}
Return value of reducers
t :: %Reaxive.Rx.Impl{accu: term, action: term, active: term, name: term, on_run: term, options: term, queue: term, sources: term, subscribers: term}
Functions
Composes the internal action on received events with the given fun
. The
initial function to compose with is the identity function.
Specs:
Internal function to disconnect from the sources
Specs:
- disconnect_source(%Reaxive.Rx.Impl{accu: term, action: term, active: term, name: term, on_run: term, options: term, queue: term, sources: term, subscribers: term}, any) :: %Reaxive.Rx.Impl{accu: term, action: term, active: term, name: term, on_run: term, options: term, queue: term, sources: term, subscribers: term}
Internal function for disconnecting a single source. This function
does not change anything beyond the sources
field, in particular
no decision about inactivating or even stopping the event sequence
is taken.
Specs:
- do_action(nil | (... -> any), rx_propagate, any, any) :: {:halt | :cont, rx_propagate, any, any} | {rx_propagate, any, any}
Internal function calculating the new value
run the sequence by calling run
on all source and call the on_run
function.
Internal function for subscribing a new observer
Specs:
- emit(t, rx_propagate) :: t
Either emits a value or puts it into the queue
This function sets the internal action on received events before the event is propagated to the subscribers. An initial accumulator value can also be provided.
All sources of Rx. Useful for debugging.
All request-reply calls for setting up the Rx.
Asynchronous callback. Used for processing values and subscription.
Specs:
- handle_event(t, rx_propagate) :: t
Internal function to handles the various events, in particular disconnects
the source which is sending a on_completed
.
Specs:
- handle_value(t, rx_propagate) :: t
Internal function to handle new values, errors or completions. If state.action
is
:nil
, the value is propagated without any modification.
Specs:
- notify({reduce_tag, rx_propagate}, t) :: t
Internal function to notify subscribers, knows about ignoring notifies.
The last regular message
An error has occured, the pipeline will be aborted.
Process the next value
Sets the on_run function, which is called for the first subscription.
Starts the event sequence
Sets the auto_stop flag for the running Rx.
Sets the disposable event sequence source
. This is needed for proper unsubscribing
from the source
when terminating the sequence.
Specs:
- start :: {:ok, Observable.t}
Starts the Rx Impl. If auto_stop
is true, the Impl
finishes after completion or
after an error or after unsubscribing the last subscriber.
Specs:
- start(nil | String.t, Keyword.t) :: {:ok, Observable.t}
Specs:
- subscribe(Observable.t, Observer.t) :: {Observable.t, (() -> :ok)}
Subscribes a new observer. Returns a function for unsubscribing the observer.
Fails grafecully with an on_error
message to the observer, if the
observable is not or no longer available. In this case, an do-nothing unsubciption
functions is returned (since no subscription has occured in the first place).
TODO:
The typing is not correct, we need to return subscriptions, also in the error case!
All subscribers of Rx. Useful for debugging.
Internal callback function at termination for clearing resources
Internal predicate to check if we
terminate ourselves.
Unsubscribes an observer
from the event sequence. If the event sequence
does not exist any longer, the caller must handle any problems. Usually, this
error handling is done within a subscription such that a “real” client has not
consider this.