Function web_thread::web::has_block_support
source · pub fn has_block_support() -> bool
Available on
Web
only.Expand description
Returns true
if the current thread supports blocking.
§Notes
Very notably, the thread containing Window
(often called the main thread
on Web), does not support blocking.
Currently known thread types to support blocking:
- Dedicated worker.
- Shared worker (currently only on Chromium based browsers).
Currently known thread types to not support blocking:
Window
(often called the main thread on Web).- Service worker.
- Worklet.
§Example
use web_thread::web::{self, JoinHandleExt};
let mut handle = web_thread::spawn(|| String::from("test"));
let result = if web::has_block_support() {
handle.join().unwrap()
} else {
handle.join_async().await.unwrap()
};