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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//! Macros for user with Ringolo (copied from tokio-macros)
/// Marks async function to be executed by the selected runtime. This macro
/// helps set up a `Runtime` without requiring the user to use Runtime or Builder.
///
/// Note: This macro is designed to be simplistic and targets applications that
/// do not require a complex setup. If the provided functionality is not
/// sufficient, you may be interested in using `runtime::Builder` which provides
/// a more powerful interface.
///
/// # Non-worker async function
///
/// Note that the async function marked with this macro does not run as a
/// worker. The expectation is that other tasks are spawned by the function here.
/// Awaiting on other futures from the function provided here will not
/// perform as fast as those spawned as workers.
///
/// # Runtime flavors
///
/// The macro can be configured with a `flavor` parameter to select
/// different runtime configurations.
///
/// ## Task Stealing Runtime (multi-thread)
///
/// To use the task stealing runtime, the macro can be configured using
///
/// ```no_run
/// #[ringolo::main(flavor = "stealing", worker_threads = 10)]
/// # async fn main() {}
/// ```
///
/// The `worker_threads` option configures the number of worker threads, and
/// defaults to the number of cpus on the system. This is the default flavor.
///
/// ## Local (current-thread)
///
/// To use the local runtime the macro can be configured using
///
/// ```rust
/// #[ringolo::main(flavor = "local")]
/// # async fn main() {}
/// ```
///
/// # Function arguments
///
/// Function arguments are NOT allowed.
///
/// # Usage
///
/// ## Using the stealing runtime (default runtime)
///
/// ```no_run
/// #[ringolo::main]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
///
/// Equivalent code not using `#[ringolo::main]`
///
/// ```no_run
/// fn main() {
/// ringolo::runtime::Builder::new_stealing()
/// .try_build()
/// .unwrap()
/// .block_on(async {
/// println!("Hello world");
/// })
/// }
/// ```
///
/// ## Using the local runtime
///
/// ```rust
/// #[ringolo::main(flavor = "local")]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
///
/// Equivalent code not using `#[ringolo::main]`
///
/// ```rust
/// fn main() {
/// ringolo::runtime::Builder::new_local()
/// .try_build()
/// .unwrap()
/// .block_on(async {
/// println!("Hello world");
/// })
/// }
/// ```
///
/// ## Set number of worker threads
///
/// ```no_run
/// #[ringolo::main(worker_threads = 2)]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
///
/// Equivalent code not using `#[ringolo::main]`
///
/// ```no_run
/// fn main() {
/// ringolo::runtime::Builder::new_stealing()
/// .worker_threads(2)
/// .try_build()
/// .unwrap()
/// .block_on(async {
/// println!("Hello world");
/// })
/// }
/// ```
/// Marks async function to be executed by runtime, suitable to test environment.
/// This macro helps set up a `Runtime` without requiring the user to use `Runtime`
/// or `Builder` directly.
///
/// Note: This macro is designed to be simplistic and targets applications that
/// do not require a complex setup. If the provided functionality is not
/// sufficient, you may be interested in using `Builder` which provides a more
/// powerful interface.
///
/// # Stealing runtime
///
/// To use the multi-threaded runtime, the macro can be configured using
///
/// ```no_run
/// #[ringolo::test(flavor = "stealing", worker_threads = 1)]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// The `worker_threads` option configures the number of worker threads, and
/// defaults to the number of cpus on the system.
///
/// # Local runtime
///
/// The default test runtime is single-threaded. Each test gets a
/// separate local runtime.
///
/// ```no_run
/// #[ringolo::test]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// ## Usage
///
/// ### Using the stealing runtime
///
/// ```no_run
/// #[ringolo::test(flavor = "stealing")]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// Equivalent code not using `#[ringolo::test]`
///
/// ```no_run
/// #[test]
/// fn my_test() {
/// ringolo::runtime::Builder::new_stealing()
/// .try_build()
/// .unwrap()
/// .block_on(async {
/// assert!(true);
/// })
/// }
/// ```
///
/// ### Using local runtime
///
/// ```no_run
/// #[ringolo::test]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// Equivalent code not using `#[ringolo::test]`
///
/// ```no_run
/// #[test]
/// fn my_test() {
/// ringolo::runtime::Builder::new_local()
/// .try_build()
/// .unwrap()
/// .block_on(async {
/// assert!(true);
/// })
/// }
/// ```
///
/// ### Set number of worker threads
///
/// ```no_run
/// #[ringolo::test(flavor = "stealing", worker_threads = 2)]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// Equivalent code not using `#[ringolo::test]`
///
/// ```no_run
/// #[test]
/// fn my_test() {
/// ringolo::runtime::Builder::new_stealing()
/// .worker_threads(2)
/// .try_build()
/// .unwrap()
/// .block_on(async {
/// assert!(true);
/// })
/// }
/// ```