ActiveAction

Type Alias ActiveAction 

Source
pub type ActiveAction = Action<Active>;
Expand description

A convenience type alias for an active action.

Aliased Type§

pub struct ActiveAction { /* private fields */ }

Implementations§

Source§

impl ActiveAction

Source

pub fn active(service: ActionService) -> Self

Create an active actionable from a given action service.

Source

pub fn into_inner(self) -> ActionService

Get a reference to the inner action service.

Source

pub fn handle_frame(&mut self, frame: Frame) -> FrameFuture

Handle a frame using an active actionable.

Source

pub fn into_stream(self) -> (impl Stream<Item = Result<Frame>>, FrameOutbox)

Turn the active actionable into a stream that emits frames returned by the interior service.

Take an active actionable into a stream and a stream handle. The stream handle can be used in one part of an application to send frames to the actionable wherever it is being used, and the stream will yield any frames returned from the actionable. This is useful for creating background tasks out of either the handle or the stream itself, for example to create a frame emitter out of an external event source.

In order for the stream to be consumed, it needs to be pinned first. This can be done by calling tokio::pin! on the stream before consuming it.

§Example
use futures::StreamExt;
use intrepid::{Action, Frame, IntoFrame, Service};

#[tokio::main]
async fn main() {
    let action = |name: String| async move { format!("Hello, {}!", name).into_frame() };

    let actionable = action.as_into_actionable().into_actionable(());

    let (mut stream, mut handle) = actionable.into_stream();

    tokio::spawn(async move {
        handle.send("Alice".to_string()).await.unwrap();
        handle.send("Bob".to_string()).await.unwrap();
    });

    tokio::pin!(stream);

    while let Some(frame) = stream.next().await {
        println!("{:?}", frame);
    }
}

Trait Implementations§

Source§

impl From<BoxCloneService<Frame, Frame, Error>> for ActiveAction

Source§

fn from(action_service: ActionService) -> Self

Converts to this type from the input type.
Source§

impl<IntoFrame> Service<IntoFrame> for ActiveAction
where IntoFrame: Into<Frame> + Clone + Send + 'static,

Source§

type Response = Frame

Responses given by the service.
Source§

type Error = Error

Errors produced by the service.
Source§

type Future = FrameFuture

The future response value.
Source§

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
Source§

fn call(&mut self, frame: IntoFrame) -> Self::Future

Process the request and return the response asynchronously. Read more