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
use Future;
use Pin;
use crateDriverCtx;
use crate;
/// Trait for async connection handlers.
///
/// Consumers implement this trait to handle connections using `async fn` code
/// instead of push-based
/// callbacks. Each accepted connection gets a long-lived async task that runs
/// for the connection's lifetime.
///
/// # Example
///
/// ```no_run
/// use std::future::Future;
/// use ringline::{AsyncEventHandler, ConnCtx, ParseResult};
///
/// struct EchoHandler;
///
/// impl AsyncEventHandler for EchoHandler {
/// fn on_accept(&self, conn: ConnCtx) -> impl Future<Output = ()> + 'static {
/// async move {
/// loop {
/// let n = conn.with_data(|data| {
/// // Echo back everything received.
/// conn.send_nowait(data).ok();
/// ringline::ParseResult::Consumed(data.len())
/// }).await;
/// if n == 0 {
/// break;
/// }
/// }
/// }
/// }
///
/// fn create_for_worker(worker_id: usize) -> Self {
/// EchoHandler
/// }
/// }
/// ```