Skip to content

Commit d41ff3f

Browse files
committed
tokio-macros: add docs for flavor = "local"
1 parent a0ca77e commit d41ff3f

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

tokio-macros/src/lib.rs

100644100755
Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ use proc_macro::TokenStream;
4646
/// Awaiting on other futures from the function provided here will not
4747
/// perform as fast as those spawned as workers.
4848
///
49-
/// # Multi-threaded runtime
49+
/// # Runtime flavors
50+
///
51+
/// The macro can be configured with a `flavor` parameter to select
52+
/// different runtime configurations.
53+
///
54+
/// ## Multi-threaded
5055
///
5156
/// To use the multi-threaded runtime, the macro can be configured using
5257
///
@@ -61,7 +66,7 @@ use proc_macro::TokenStream;
6166
/// Note: The multi-threaded runtime requires the `rt-multi-thread` feature
6267
/// flag.
6368
///
64-
/// # Current thread runtime
69+
/// ## Current-thread
6570
///
6671
/// To use the single-threaded runtime known as the `current_thread` runtime,
6772
/// the macro can be configured using
@@ -71,13 +76,13 @@ use proc_macro::TokenStream;
7176
/// # async fn main() {}
7277
/// ```
7378
///
74-
/// ## Function arguments:
79+
/// # Function arguments
7580
///
76-
/// Arguments are allowed for any functions aside from `main` which is special
81+
/// Arguments are allowed for any functions, aside from `main` which is special.
7782
///
78-
/// ## Usage
83+
/// # Usage
7984
///
80-
/// ### Using the multi-thread runtime
85+
/// ## Using the multi-threaded runtime
8186
///
8287
/// ```rust
8388
/// #[tokio::main]
@@ -100,7 +105,7 @@ use proc_macro::TokenStream;
100105
/// }
101106
/// ```
102107
///
103-
/// ### Using current thread runtime
108+
/// ## Using the current-thread runtime
104109
///
105110
/// The basic scheduler is single-threaded.
106111
///
@@ -125,7 +130,37 @@ use proc_macro::TokenStream;
125130
/// }
126131
/// ```
127132
///
128-
/// ### Set number of worker threads
133+
/// ## Using the local runtime
134+
///
135+
/// Available with [`tokio_unstable`](../tokio#unstable-features) only.
136+
///
137+
/// The [local runtime](../tokio/runtime/struct.LocalRuntime.html) is
138+
/// similar to the current-thread runtime but supports
139+
/// [`task::spawn_local`](../tokio/task/fn.spawn_local.html).
140+
///
141+
/// ```rust
142+
/// #[tokio::main(flavor = "local")]
143+
/// async fn main() {
144+
/// println!("Hello world");
145+
/// }
146+
/// ```
147+
///
148+
/// Equivalent code not using `#[tokio::main]`
149+
///
150+
/// ```rust
151+
/// fn main() {
152+
/// tokio::runtime::Builder::new_current_thread()
153+
/// .enable_all()
154+
/// .build_local(tokio::runtime::LocalOptions::default())
155+
/// .unwrap()
156+
/// .block_on(async {
157+
/// println!("Hello world");
158+
/// })
159+
/// }
160+
/// ```
161+
///
162+
///
163+
/// ## Set number of worker threads
129164
///
130165
/// ```rust
131166
/// #[tokio::main(worker_threads = 2)]
@@ -149,7 +184,7 @@ use proc_macro::TokenStream;
149184
/// }
150185
/// ```
151186
///
152-
/// ### Configure the runtime to start with time paused
187+
/// ## Configure the runtime to start with time paused
153188
///
154189
/// ```rust
155190
/// #[tokio::main(flavor = "current_thread", start_paused = true)]
@@ -175,7 +210,7 @@ use proc_macro::TokenStream;
175210
///
176211
/// Note that `start_paused` requires the `test-util` feature to be enabled.
177212
///
178-
/// ### Rename package
213+
/// ## Rename package
179214
///
180215
/// ```rust
181216
/// use tokio as tokio1;
@@ -202,7 +237,7 @@ use proc_macro::TokenStream;
202237
/// }
203238
/// ```
204239
///
205-
/// ### Configure unhandled panic behavior
240+
/// ## Configure unhandled panic behavior
206241
///
207242
/// Available options are `shutdown_runtime` and `ignore`. For more details, see
208243
/// [`Builder::unhandled_panic`].

0 commit comments

Comments
 (0)