pub struct CommandContext<Effect, Event> { /* private fields */ }Expand description
Context enabling tasks to communicate with the parent Command, specifically submit effects, events and spawn further tasks
Implementations§
Source§impl<Effect, Event> CommandContext<Effect, Event>
impl<Effect, Event> CommandContext<Effect, Event>
Sourcepub fn notify_shell<Op>(&self, operation: Op)
pub fn notify_shell<Op>(&self, operation: Op)
Create a one-off notification to the shell. This method returns immediately.
Sourcepub fn request_from_shell<Op>(&self, operation: Op) -> ShellRequest<Op::Output>
pub fn request_from_shell<Op>(&self, operation: Op) -> ShellRequest<Op::Output>
Create a one-off request for an operation. Returns a future which eventually resolves with the output of the operation provided by the shell.
§Cancellation behaviour
ShellRequest futures may never resolve, if the corresponding [RequestHandle]
is dropped by the shell. Such cases are detected by the Command and the owning task is aborted.
That is to say - any .await point on a ShellRequest is a potential abort point for the
enclosing future.
Sourcepub fn stream_from_shell<Op>(&self, operation: Op) -> ShellStream<Op::Output>
pub fn stream_from_shell<Op>(&self, operation: Op) -> ShellStream<Op::Output>
Create a stream request for an operation. Returns a stream producing the with the output of the operation every time it is provided by the shell.
§Cancellation behaviour
ShellStream futures may never resolve, if the corresponding [RequestHandle]
is dropped by the shell. Such cases are detected by the Command and the owning task is aborted.
That is to say - any .await point on a ShellRequest is a potential abort point for the
enclosing future.
Sourcepub fn send_event(&self, event: Event)
pub fn send_event(&self, event: Event)
Send an event which should be handed to the update function. This is used to communicate the result (or a sequence of results) of a command back to the app so that state can be updated accordingly
Sourcepub fn spawn<F, Fut>(&self, make_future: F) -> JoinHandle
pub fn spawn<F, Fut>(&self, make_future: F) -> JoinHandle
Spawn a new task within the same command. The task will execute concurrently with other tasks within the command until it either concludes, is aborted, or until the parent command is aborted.
Returns a JoinHandle which can be used as a future to await the completion of the task. It can also
be used to abort the task.