1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Async/await syntax.
//!
//! ```
//! # #![feature(conservative_impl_trait)]
//! # #![feature(generators)]
//! # #![feature(never_type)]
//! # #![feature(prelude_import)]
//! # #![feature(proc_macro)]
//! # #[macro_use] extern crate drone_core;
//! # extern crate futures;
//! # #[prelude_import] use drone_core::prelude::*;
//! # use futures::executor::Notify;
//! # struct NotifyNop;
//! # const NOTIFY_NOP: &NotifyNop = &NotifyNop;
//! # impl Notify for NotifyNop { fn notify(&self, _id: usize) {} }
//! use drone_core::sync::spsc::oneshot;
//! use futures::executor;
//!
//! fn plus_one(
//!   rx: oneshot::Receiver<usize, !>,
//! ) -> impl Future<Item = usize, Error = oneshot::RecvError<!>> {
//!   AsyncFuture::new(|| {
//!     let number = await!(rx)?;
//!     Ok(number + 1)
//!   })
//! }
//!
//! fn main() {
//!   let (tx, rx) = oneshot::channel::<usize, !>();
//!   let mut executor = executor::spawn(plus_one(rx));
//!   assert_eq!(tx.send(Ok(1)), Ok(()));
//!   assert_eq!(
//!     executor.poll_future_notify(&NOTIFY_NOP, 0),
//!     Ok(Async::Ready(2))
//!   );
//! }
//! ```
//!
//! ```
//! # #![feature(conservative_impl_trait)]
//! # #![feature(generators)]
//! # #![feature(never_type)]
//! # #![feature(prelude_import)]
//! # #![feature(proc_macro)]
//! # #[macro_use] extern crate drone_core;
//! # extern crate futures;
//! # #[prelude_import] use drone_core::prelude::*;
//! # use futures::executor::Notify;
//! # struct NotifyNop;
//! # const NOTIFY_NOP: &NotifyNop = &NotifyNop;
//! # impl Notify for NotifyNop { fn notify(&self, _id: usize) {} }
//! use drone_core::sync::spsc::ring;
//! use futures::executor;
//!
//! fn sum(
//!   rx: ring::Receiver<usize, !>,
//! ) -> impl Future<Item = usize, Error = !> {
//!   AsyncFuture::new(|| {
//!     let mut sum = 0;
//!     await_for!(number in rx; {
//!       sum += number;
//!     });
//!     Ok(sum)
//!   })
//! }
//!
//! fn main() {
//!   let (mut tx, rx) = ring::channel::<usize, !>(8);
//!   let mut executor = executor::spawn(sum(rx));
//!   assert_eq!(tx.send_overwrite(3), Ok(()));
//!   assert_eq!(tx.send_overwrite(4), Ok(()));
//!   assert_eq!(tx.send_overwrite(5), Ok(()));
//!   drop(tx);
//!   assert_eq!(
//!     executor.poll_future_notify(&NOTIFY_NOP, 0),
//!     Ok(Async::Ready(12))
//!   );
//! }
//! ```

mod async_future;
#[macro_use]
mod await;

pub use self::async_future::AsyncFuture;