-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
14 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use core::panic; | ||
use lazy_static::lazy_static; | ||
use std::{ | ||
collections::HashMap, | ||
|
@@ -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; | ||
|
||
|
@@ -44,7 +45,6 @@ impl ZRuntime { | |
} | ||
|
||
fn init(&self) -> Result<Runtime> { | ||
// dbg!(*ZRUNTIME_CONFIG); | ||
let config = &ZRUNTIME_CONFIG; | ||
|
||
let thread_name = format!("{self:?}"); | ||
|
@@ -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)) | ||
} | ||
} | ||
|
@@ -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") }); | ||
} |