mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Start tokio runtime on main thread and enter context there, so non-async code can spawn tasks too
This commit is contained in:
parent
db6907dea5
commit
dd0ce06828
15
src/main.rs
15
src/main.rs
@ -46,11 +46,16 @@ fn main() -> Result<(), Error> {
|
|||||||
let settings = crate::settings::Settings::blocking_load()?;
|
let settings = crate::settings::Settings::blocking_load()?;
|
||||||
*GLOBALS.settings.blocking_write() = settings;
|
*GLOBALS.settings.blocking_write() = settings;
|
||||||
|
|
||||||
// Start async code
|
// We create and enter the runtime on the main thread so that
|
||||||
// We do this on a separate thread because egui is most portable by
|
// non-async code can have a runtime context within which to spawn
|
||||||
// being on the main thread.
|
// async tasks.
|
||||||
let async_thread = thread::spawn(|| {
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let _main_rt = rt.enter(); // <-- this allows it.
|
||||||
|
|
||||||
|
// We run our main async code on a separate thread, not just a
|
||||||
|
// separate task. This leave the main thread for UI work only.
|
||||||
|
// egui is most portable when it is on the main thread.
|
||||||
|
let async_thread = thread::spawn(move || {
|
||||||
rt.block_on(tokio_main());
|
rt.block_on(tokio_main());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user