pub struct StreamBuilder<Effect, Event, Task> { /* private fields */ }
Expand description
A builder of stream command
Implementations§
Source§impl<Effect, Event, Task, T> StreamBuilder<Effect, Event, Task>
impl<Effect, Event, Task, T> StreamBuilder<Effect, Event, Task>
pub fn new<F>(make_task: F) -> Self
pub fn map<F, U>( self, map: F, ) -> StreamBuilder<Effect, Event, impl Stream<Item = U>>
Sourcepub fn then_request<F, U, NextTask>(
self,
make_next_builder: F,
) -> StreamBuilder<Effect, Event, impl Stream<Item = U>>where
F: Fn(T) -> RequestBuilder<Effect, Event, NextTask> + Send + 'static,
NextTask: Future<Output = U> + Send + 'static,
pub fn then_request<F, U, NextTask>(
self,
make_next_builder: F,
) -> StreamBuilder<Effect, Event, impl Stream<Item = U>>where
F: Fn(T) -> RequestBuilder<Effect, Event, NextTask> + Send + 'static,
NextTask: Future<Output = U> + Send + 'static,
Chain a RequestBuilder
to run after completion of this StreamBuilder
,
passing the result to the provided closure make_next_builder
.
The returned value of the closure must be a StreamBuilder
, which
can represent some more work to be done before the composed future
is finished.
If you want to chain a subscription, use Self::then_stream
instead.
The closure make_next_builder
is only run after successful completion
of the self
future.
Note that this function consumes the receiving StreamBuilder
and returns a
new one that represents the composition.
§Example
let mut cmd: Command<Effect, Event> = Command::stream_from_shell(AnOperation::More(1))
.then_request(|first| {
let AnOperationOutput::Other(first) = first else {
panic!("Invalid output!")
};
let second = first + 1;
Command::request_from_shell(AnOperation::More(second))
})
.then_send(Event::Completed);
let Effect::AnEffect(mut request) = cmd.effects().next().unwrap();
assert_eq!(request.operation, AnOperation::More(1));
request
.resolve(AnOperationOutput::Other(1))
.expect("to resolve");
let Effect::AnEffect(mut request) = cmd.effects().next().unwrap();
assert_eq!(request.operation, AnOperation::More(2));
Sourcepub fn then_stream<F, U, NextTask>(
self,
make_next_builder: F,
) -> StreamBuilder<Effect, Event, impl Stream<Item = U>>where
F: Fn(T) -> StreamBuilder<Effect, Event, NextTask> + Send + 'static,
NextTask: Stream<Item = U> + Send + 'static,
pub fn then_stream<F, U, NextTask>(
self,
make_next_builder: F,
) -> StreamBuilder<Effect, Event, impl Stream<Item = U>>where
F: Fn(T) -> StreamBuilder<Effect, Event, NextTask> + Send + 'static,
NextTask: Stream<Item = U> + Send + 'static,
Chain another StreamBuilder
to run after completion of this one,
passing the result to the provided closure make_next_builder
.
The returned value of the closure must be a StreamBuilder
, which
can represent some more work to be done before the composed future
is finished.
If you want to chain a request, use Self::then_request
instead.
The closure make_next_builder
is only run after successful completion
of the self
future.
Note that this function consumes the receiving StreamBuilder
and returns a
new one that represents the composition.
§Example
let mut cmd: Command<Effect, Event> = Command::stream_from_shell(AnOperation::More(1))
.then_stream(|first| {
let AnOperationOutput::Other(first) = first else {
panic!("Invalid output!")
};
let second = first + 1;
Command::stream_from_shell(AnOperation::More(second))
})
.then_send(Event::Completed);
let Effect::AnEffect(mut request) = cmd.effects().next().unwrap();
assert_eq!(request.operation, AnOperation::More(1));
request
.resolve(AnOperationOutput::Other(1))
.expect("to resolve");
let Effect::AnEffect(mut request) = cmd.effects().next().unwrap();
assert_eq!(request.operation, AnOperation::More(2));
Sourcepub fn then_send<E>(self, event: E) -> Command<Effect, Event>
pub fn then_send<E>(self, event: E) -> Command<Effect, Event>
Create the command in an evented context
Sourcepub fn into_stream(self, ctx: CommandContext<Effect, Event>) -> Task
pub fn into_stream(self, ctx: CommandContext<Effect, Event>) -> Task
Convert the stream builder into a stream to use in an async context