[−][src]Trait reducer::Dispatcher
Trait for types that allow dispatching actions.
Associated Types
type Output
Required methods
Loading content...Implementations
impl<A, E> dyn Dispatcher<A, Output = Result<(), E>>
[src]
pub fn from_sink<T>(sink: T) -> AsyncDispatcher<T> where
T: Sink<A, Error = E> + Unpin,
[src]
T: Sink<A, Error = E> + Unpin,
Adapts any type that implements Sink
as a Dispatcher
(requires async
).
Example
use reducer::*; use futures::channel::mpsc::channel; use futures::executor::block_on_stream; use std::thread; let (tx, rx) = channel(0); let mut dispatcher = Dispatcher::<_, Output = _>::from_sink(tx); thread::spawn(move || { dispatcher.dispatch(1); dispatcher.dispatch(1); dispatcher.dispatch(2); dispatcher.dispatch(3); dispatcher.dispatch(5); dispatcher.dispatch(8); }); assert_eq!(block_on_stream(rx).collect::<Vec<u8>>(), vec![1, 1, 2, 3, 5, 8]);
Implementors
impl<A, S, R> Dispatcher<A> for Store<S, R> where
S: Reducer<A>,
R: Reactor<S>,
[src]
S: Reducer<A>,
R: Reactor<S>,
type Output = Result<(), R::Error>
fn dispatch(&mut self, action: A) -> Self::Output
[src]
Updates the state via Reducer::reduce
and notifies the Reactor
,
returning the result of calling Reactor::react
with a reference
to the new state.
impl<A, T> Dispatcher<A> for AsyncDispatcher<T> where
T: Sink<A> + Unpin,
[src]
T: Sink<A> + Unpin,
type Output = Result<(), T::Error>
Either confirmation that action has been dispatched through the sink or the reason why not.
fn dispatch(&mut self, action: A) -> Self::Output
[src]
Sends an action through the sink.
Once this call returns, the action may or may not have taken effect, but it's guaranteed to eventually do, unless the sink is closed in between.