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
108
109
110
111
112
113
114
115
116
117
118
119
120
use crate;
use crate::;
use Future;
/// It does next steps on each core:
///
/// 1 - Initializes the [`Executor`] with provided [`Config`];
///
/// 2 - Spawns `local_future` using `creator`;
///
/// 3 - Runs the [`Executor`].
///
/// # Example
///
/// ## High-performance echo server
///
/// ```no_run
/// use orengine::{run_on_all_cores_with_config, local_executor};
/// use orengine::runtime::Config;
/// use orengine::io::{full_buffer, AsyncBind, AsyncAccept};
/// use orengine::net::{Stream, TcpListener, TcpStream};
///
/// async fn handle_stream<S: Stream>(mut stream: S) {
/// loop {
/// stream.poll_recv().await.unwrap();
/// let mut buf = full_buffer();
/// buf.set_len_to_capacity();
/// let n = stream.recv(&mut buf).await.unwrap();
/// if n == 0 {
/// break;
/// }
/// stream.send_all(&buf.slice(..n)).await.unwrap();
/// }
/// }
///
/// fn main() {
/// run_on_all_cores_with_config(|| async {
/// let mut listener = TcpListener::bind("127.0.0.1:8080").await.unwrap();
/// loop {
/// let (stream, _) = listener.accept().await.unwrap();
/// local_executor().spawn_local(async move {
/// handle_stream(stream).await;
/// });
/// }
/// }, Config::default().set_numbers_of_thread_workers(0).disable_work_sharing());
/// }
/// ```
/// It does next steps on each core:
///
/// 1 - Initializes the [`Executor`];
///
/// 2 - Spawns `local` future using `creator`;
///
/// 3 - Runs the [`Executor`].
///
/// # Example
///
/// ## High-performance echo server
///
/// ```no_run
/// use orengine::{run_on_all_cores, local_executor};
/// use orengine::io::{full_buffer, AsyncBind, AsyncAccept};
/// use orengine::net::{Stream, TcpListener, TcpStream};
///
/// async fn handle_stream<S: Stream>(mut stream: S) {
/// loop {
/// stream.poll_recv().await.unwrap();
/// let mut buf = full_buffer();
/// buf.set_len_to_capacity();
/// let n = stream.recv(&mut buf).await.unwrap();
/// if n == 0 {
/// break;
/// }
/// stream.send_all(&buf.slice(..n)).await.unwrap();
/// }
/// }
///
/// fn main() {
/// run_on_all_cores(|| async {
/// let mut listener = TcpListener::bind("127.0.0.1:8080").await.unwrap();
/// loop {
/// let (stream, _) = listener.accept().await.unwrap();
/// local_executor().spawn_local(async move {
/// handle_stream(stream).await;
/// });
/// }
/// });
/// }
/// ```