Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #835 #844

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") });
}