Function web_thread::web::spawn_with_message
source · pub fn spawn_with_message<F1, F2, T, M>(f: F1, message: M) -> JoinHandle<T>where
F1: 'static + FnOnce(M) -> F2 + Send,
F2: 'static + Future<Output = T>,
T: 'static + Send,
M: 'static + MessageSend,
Available on
Web
and crate feature message
only.Expand description
spawn_async()
with message.
For a more complete documentation see spawn_async()
.
§Panics
- If the main thread does not support spawning threads, see
has_spawn_support()
. - If
message
was unable to be cloned.
§Example
use web_sys::{HtmlCanvasElement, OffscreenCanvas};
use web_thread::web::{self, JoinHandleExt};
use web_thread::web::message::TransferableWrapper;
let canvas: HtmlCanvasElement = canvas;
let message = TransferableWrapper(canvas.transfer_control_to_offscreen().unwrap());
web::spawn_with_message(
|message| async move {
let canvas: OffscreenCanvas = message.0;
// Do work.
},
message,
)
.join_async()
.await
.unwrap();