MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / execute_across_threads

Function execute_across_threads

tests/all/async_functions.rs:478–495  ·  view source on GitHub ↗

This will execute the `future` provided to completion and each invocation of `poll` for the future will be executed on a separate thread.

(future: F)

Source from the content-addressed store, hash-verified

476/// This will execute the `future` provided to completion and each invocation of
477/// `poll` for the future will be executed on a separate thread.
478pub async fn execute_across_threads<F>(future: F) -> F::Output
479where
480 F: Future + Send + 'static,
481 F::Output: Send,
482{
483 let mut future = Box::pin(future);
484 loop {
485 let once = PollOnce::new(future);
486 let handle = tokio::runtime::Handle::current();
487 let result = std::thread::spawn(move || handle.block_on(once))
488 .join()
489 .unwrap();
490 match result {
491 Ok(val) => break val,
492 Err(f) => future = f,
493 }
494 }
495}
496
497#[tokio::test]
498#[cfg_attr(miri, ignore)]

Callers 6

resume_separate_threadFunction · 0.85
resume_separate_thread2Function · 0.85
resume_separate_threadFunction · 0.85
drop_resource_asyncFunction · 0.85

Calls 5

spawnFunction · 0.85
block_onMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected