use futures::channel::oneshot; use futures::future::{self, Future, FutureExt, TryFutureExt}; use futures::task::{Context, Poll}; use futures_test::future::FutureTestExt; use pin_project::pin_project; use std::pin::Pin; use std::sync::mpsc;
#[test] fn map_ok() { // The closure given to `map_ok` should have been dropped by the time `map` // runs. let (tx1, rx1) = mpsc::channel::<()>(); let (tx2, rx2) = mpsc::channel::<()>();
future::ready::<Result<i32, i32>>(Err(1))
.map_ok(move |_| { let _tx1 = tx1;
panic!("should not run");
})
.map(move |_| {
assert!(rx1.recv().is_err());
tx2.send(()).unwrap()
})
.run_in_background();
rx2.recv().unwrap();
}
#[test] fn map_err() { // The closure given to `map_err` should have been dropped by the time `map` // runs. let (tx1, rx1) = mpsc::channel::<()>(); let (tx2, rx2) = mpsc::channel::<()>();
future::ready::<Result<i32, i32>>(Ok(1))
.map_err(move |_| { let _tx1 = tx1;
panic!("should not run");
})
.map(move |_| {
assert!(rx1.recv().is_err());
tx2.send(()).unwrap()
})
.run_in_background();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.