Skip to main content

ResultHandle

Type Alias ResultHandle 

Source
pub type ResultHandle<I, O, E> = Handle<I, Result<O, E>>;
Expand description

Handle return value is a Result

Aliased Type§

pub struct ResultHandle<I, O, E> {
    pub n: usize,
    /* private fields */
}

Fields§

§n: usize

Implementations§

Source§

impl<I, O, E> ResultHandle<I, O, E>
where I: Send + 'static, O: Send + 'static, E: Send + 'static,

Source

pub fn and<U, V, EN>( self, rhs: ResultHandle<U, V, EN>, ) -> ResultHandle<(I, U), (O, V), Error>
where E: Sync + Error, U: Send + 'static, V: Send + 'static, EN: Sync + Send + Error + 'static,

ResultHandle<I, O, E> + ResultHandle<U, V, EN> => ResultHandle<(I, U), (O, V), anyhow::Error>

use tokiactor::*;
use tokio;
use thiserror;

#[derive(Debug, thiserror::Error)]
pub enum Error{}

tokio::runtime::Runtime::new().unwrap().block_on(
    async move {
        let r = Handle::new(1)
            .spawn(move |i: i32| {
                Result::<i32, Error>::Ok(i+1)
             })
            .and(
                Handle::new(1).spawn(move |i: i32| {
                Result::<i32, Error>::Ok(i*1)
            })
        ).handle((1, 1)).await;
        assert_eq!(r.unwrap(), (2, 1));
    }
);
Source

pub fn and_then<P, EN>( self, rhs: ResultHandle<O, P, EN>, ) -> ResultHandle<I, P, Error>
where E: Sync + Error, P: Send + 'static, EN: Sync + Send + Error + 'static,

ResultHandle<I, O, E> | ResultHandle<O, P, EN> => ResultHandle<I, P, anyhow::Error>

use tokiactor::*;
use tokio;
use thiserror;

#[derive(Debug, thiserror::Error)]
pub enum Error{}

tokio::runtime::Runtime::new().unwrap().block_on(
    async move {
        let r = Handle::new(1)
            .spawn(move |i: i32| {
                Result::<i32, Error>::Ok(i+1)
             })
            .and_then(
                Handle::new(1).spawn(move |i: i32| {
                Result::<i32, Error>::Ok(i*10)
            })
        ).handle(1).await;
        assert_eq!(r.unwrap(), 20);
    }
);
Source

pub fn map<P>(self, rhs: Handle<O, P>) -> ResultHandle<I, P, E>
where P: Send + 'static,

ResultHandle<I, O, E> | Handle<O, P> => ResultHandle<I, P, E>

use tokiactor::*;
use tokio;
use thiserror;

#[derive(Debug, thiserror::Error)]
pub enum Error{}

tokio::runtime::Runtime::new().unwrap().block_on(
    async move {
        let r = Handle::new(1)
            .spawn(move |i: i32| {
                Result::<i32, Error>::Ok(i+1)
             })
            .map(
                Handle::new(1).spawn(move |i: i32| {
                i*10
            })
        ).handle(1).await;
        assert_eq!(r.unwrap(), 20);
    }
);
Source

pub fn ok(self) -> OptionHandle<I, O>

ResultHandle<I, O, E> => OptionHandle<I, O>

use tokiactor::*;
use tokio;
use thiserror;

#[derive(Debug, thiserror::Error)]
pub enum Error{}

tokio::runtime::Runtime::new().unwrap().block_on(
    async move {
        let r = Handle::new(1)
            .spawn(move |i: i32| {
                Result::<i32, Error>::Ok(i+1)
             }).ok().handle(1).await;
        assert_eq!(r.unwrap(), 2);
    }
);