ps-promise 0.1.0-16

Promise-like owned futures
Documentation
use std::future::Future;

use crate::{Promise, PromiseRejection};

impl<T, E> Promise<T, E>
where
    T: Send + Unpin + 'static,
    E: PromiseRejection,
{
    pub fn catch<TO, EO, F, Fut>(self, recover: F) -> Promise<TO, EO>
    where
        TO: From<T> + Unpin + 'static,
        EO: PromiseRejection + 'static,
        F: FnOnce(E) -> Fut + Send + 'static,
        Fut: Future<Output = Result<TO, EO>> + Send + 'static,
    {
        Promise::new(async move {
            match self.await {
                Ok(value) => Ok(value.into()),
                Err(err) => recover(err).await,
            }
        })
    }
}