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
//! The runtime of completeio.
//! We don't expose the runtime struct because there could be only one runtime
//! in each thread.
//!
//! ```
//! let ans = completeio::task::block_on(async {
//! println!("Hello world!");
//! 42
//! });
//! assert_eq!(ans, 42);
//! ```
use Future;
use Task;
pub
use Runtime;
pub
thread_local!
/// Start a completeio runtime and block on the future till it completes.
///
/// ```
/// completeio::task::block_on(async {
/// // Open a file
/// let file = completeio::fs::File::open("Cargo.toml").unwrap();
///
/// let buf = Vec::with_capacity(4096);
/// // Read some data, the buffer is passed by ownership and
/// // submitted to the kernel. When the operation completes,
/// // we get the buffer back.
/// let (res, buf) = file.read_at(buf, 0).await;
/// let n = res.unwrap();
/// assert_eq!(n, buf.len());
///
/// // Display the contents
/// println!("{:?}", &buf);
/// })
/// ```
/// Spawns a new asynchronous task, returning a [`Task`] for it.
///
/// Spawning a task enables the task to execute concurrently to other tasks.
/// There is no guarantee that a spawned task will execute to completion.
///
/// ```
/// completeio::task::block_on(async {
/// let task = completeio::task::spawn(async {
/// println!("Hello from a spawned task!");
/// 42
/// });
///
/// assert_eq!(task.await, 42);
/// })
/// ```