Skip to content

Commit 42772bc

Browse files
authored
Book: Add clarification around creating tokio runtime (#1546)
Off the back of gtk-rs/gtk-rs-core#1251, this adds some additional detail to the Tokio section of the main event loop page that explains *why* the runtime is manually created, and the reasons to avoid doing it the 'normal' way.
1 parent 2ed0557 commit 42772bc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

book/src/main_event_loop.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ cargo add tokio@1 --features rt-multi-thread
275275
```
276276

277277
Since we already run the `glib` main loop on our main thread, we don't want to run the `tokio` runtime there.
278-
Let's bind it to a static variable and initialize it lazily.
278+
For this reason, we **avoid** using the `#[tokio::main]` macro or using a top-level `block_on` call.
279+
Doing this will block one of the runtime's threads with the GLib main loop, which is a waste of resources and a potential source of strange bugs.
280+
281+
Instead, the runtime is manually created and used where needed. Let's bind it to a static variable and initialize it lazily.
279282

280283
Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/main_event_loop/9/main.rs">listings/main_event_loop/9/main.rs</a>
281284

0 commit comments

Comments
 (0)