Skip to content

Commit

Permalink
Fix issue #835 (#844)
Browse files Browse the repository at this point in the history
* Fix issue #835

* Bugfix
  • Loading branch information
YuanYuYuan authored Mar 19, 2024
1 parent 27ee162 commit 03ed5d9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions commons/zenoh-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
use core::panic;
use lazy_static::lazy_static;
use std::{
collections::HashMap,
Expand All @@ -22,7 +23,7 @@ use std::{
OnceLock,
},
};
use tokio::runtime::{Handle, Runtime};
use tokio::runtime::{Handle, Runtime, RuntimeFlavor};
use zenoh_collections::Properties;
use zenoh_result::ZResult as Result;

Expand All @@ -44,7 +45,6 @@ impl ZRuntime {
}

fn init(&self) -> Result<Runtime> {
// dbg!(*ZRUNTIME_CONFIG);
let config = &ZRUNTIME_CONFIG;

let thread_name = format!("{self:?}");
Expand Down Expand Up @@ -110,6 +110,11 @@ impl ZRuntime {
where
F: Future<Output = R>,
{
if let Ok(handle) = Handle::try_current() {
if handle.runtime_flavor() == RuntimeFlavor::CurrentThread {
panic!("Zenoh runtime doesn't support Tokio's current thread scheduler. Please use multi thread scheduler instead, e.g. a multi thread scheduler with one worker thread: `#[tokio::main(flavor = \"multi_thread\", worker_threads = 1)]`");
}
}
tokio::task::block_in_place(move || self.block_on(f))
}
}
Expand Down Expand Up @@ -200,3 +205,10 @@ impl Default for ZRuntimeConfig {
}
}
}

#[should_panic(expected = "Zenoh runtime doesn't support")]
#[tokio::test]
async fn block_in_place_fail_test() {
use crate::ZRuntime;
ZRuntime::TX.block_in_place(async { println!("Done") });
}

0 comments on commit 03ed5d9

Please sign in to comment.