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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! # TCP
//! The constructors every TCP task is started from
use crate;
use Arc;
/// Talks to other programs over TCP
///
/// It doesn't implement `Task`, so a method has to be called on
/// it to get something that does
///
/// ## Behaviour
/// A connection is a value. [`Tcp::connect`] and
/// [`Listener::accept`] hand one back, and its methods build the
/// tasks that send and receive on it. [`Tcp::request`] does the
/// whole exchange in one task, for when that is all there is
///
/// ```no_run
/// # use atap::{Runtime, tcp::Tcp};
/// # use std::time::Duration;
/// # fn main() -> Result<(), atap::RuntimeError> {
/// let reply = Runtime::task(Tcp::request("example.com:80", b"GET / HTTP/1.0\r\n\r\n".as_slice()))
/// .timeout(Duration::from_secs(5))
/// .spawn()
/// .join()??;
/// # Ok(())
/// # }
/// ```
///
/// ## Waiting
/// A spawned task waiting on the network holds no thread. It
/// parks, and the runtime runs it again once its socket is ready,
/// so any number of them can wait at once
///
/// [`Runtime::block`] can't give its thread back, so a blocking
/// call waits on the calling thread instead. It can't be
/// cancelled or timed out, so spawn a task that needs a limit
///
/// ## Cancellation
/// A cancelled task comes down at once, even while it waits on a
/// silent peer, and gives back [`RuntimeError::Cancelled`]. A
/// receive puts back what it had read. A send may already have
/// sent part of its data
///
/// #### Note
/// A socket task still waiting on the network when the runtime
/// shuts down is written off, and reads [`RuntimeError::TaskFailed`]
///
/// [`Listener::accept`]: crate::tcp::Listener::accept
/// [`Runtime::block`]: crate::Runtime::block
/// [`RuntimeError::Cancelled`]: crate::RuntimeError::Cancelled
/// [`RuntimeError::TaskFailed`]: crate::RuntimeError::TaskFailed
;