ps_promise/methods/
then.rs1use std::future::Future;
2
3use crate::{Promise, PromiseRejection};
4
5impl<T, E> Promise<T, E>
6where
7 T: Send + Unpin + 'static,
8 E: PromiseRejection,
9{
10 pub fn then<TO, EO, F, Fut>(self, f: F) -> Promise<TO, EO>
11 where
12 TO: Unpin + 'static,
13 EO: PromiseRejection + From<E> + 'static,
14 F: FnOnce(T) -> Fut + Send + 'static,
15 Fut: Future<Output = Result<TO, EO>> + Send + 'static,
16 {
17 Promise::new(async move {
18 match self.await {
19 Ok(value) => f(value).await,
20 Err(err) => Err(err.into()),
21 }
22 })
23 }
24}