ps_promise/methods/map.rs
1use 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 map<TO, F, Fut>(self, f: F) -> Promise<TO, E>
11 where
12 TO: Unpin + 'static,
13 F: FnOnce(T) -> Fut + Send + 'static,
14 Fut: Future<Output = TO> + Send + 'static,
15 {
16 Promise::new(async move {
17 match self.await {
18 Ok(value) => Ok(f(value).await),
19 Err(err) => Err(err),
20 }
21 })
22 }
23}