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