From c1679baed86b133446f1b36a21da0835959fc366 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 8 Jun 2026 08:27:10 -0700 Subject: [PATCH] Rename `spawn` to `spawn_local` Rationale is listed in #1626. Closes #1626 --- crates/guest-rust/src/lib.rs | 2 +- crates/guest-rust/src/rt/async_support.rs | 2 +- crates/guest-rust/src/rt/async_support/spawn.rs | 2 +- tests/runtime-async/async/ping-pong/test.rs | 2 +- tests/runtime-async/async/yield-loop-receives-events/middle.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/guest-rust/src/lib.rs b/crates/guest-rust/src/lib.rs index 3e55de02a..a98cc7a0b 100644 --- a/crates/guest-rust/src/lib.rs +++ b/crates/guest-rust/src/lib.rs @@ -881,7 +881,7 @@ pub mod rt; #[cfg(feature = "inter-task-wakeup")] pub use rt::async_support::UnitStreamOps; #[cfg(feature = "async-spawn")] -pub use rt::async_support::spawn; +pub use rt::async_support::spawn_local; #[cfg(feature = "async")] pub use rt::async_support::{ AbiBuffer, FutureOps, FutureRead, FutureReader, FutureWrite, FutureWriteCancel, diff --git a/crates/guest-rust/src/rt/async_support.rs b/crates/guest-rust/src/rt/async_support.rs index e29c5a234..2a5218ed1 100644 --- a/crates/guest-rust/src/rt/async_support.rs +++ b/crates/guest-rust/src/rt/async_support.rs @@ -96,7 +96,7 @@ type BoxFuture<'a> = Pin + 'a>>; #[cfg(feature = "async-spawn")] mod spawn; #[cfg(feature = "async-spawn")] -pub use spawn::spawn; +pub use spawn::spawn_local; #[cfg(not(feature = "async-spawn"))] mod spawn_disabled; #[cfg(not(feature = "async-spawn"))] diff --git a/crates/guest-rust/src/rt/async_support/spawn.rs b/crates/guest-rust/src/rt/async_support/spawn.rs index 083f686e4..2dff5b378 100644 --- a/crates/guest-rust/src/rt/async_support/spawn.rs +++ b/crates/guest-rust/src/rt/async_support/spawn.rs @@ -110,6 +110,6 @@ impl<'a> Tasks<'a> { /// /// [`block_on`]: crate::block_on /// [#1305]: https://github.com/bytecodealliance/wit-bindgen/issues/1305 -pub fn spawn(future: impl Future + 'static) { +pub fn spawn_local(future: impl Future + 'static) { unsafe { SPAWNED.push(Box::pin(future)) } } diff --git a/tests/runtime-async/async/ping-pong/test.rs b/tests/runtime-async/async/ping-pong/test.rs index 457439061..d6b3e97ea 100644 --- a/tests/runtime-async/async/ping-pong/test.rs +++ b/tests/runtime-async/async/ping-pong/test.rs @@ -10,7 +10,7 @@ impl crate::exports::my::test::i::Guest for Component { async fn ping(x: FutureReader, y: String) -> FutureReader { let msg = x.await + y.as_str(); let (tx, rx) = wit_future::new(|| unreachable!()); - wit_bindgen::spawn(async move { + wit_bindgen::spawn_local(async move { tx.write(msg).await.unwrap(); }); rx diff --git a/tests/runtime-async/async/yield-loop-receives-events/middle.rs b/tests/runtime-async/async/yield-loop-receives-events/middle.rs index ab701b7e6..4979c580a 100644 --- a/tests/runtime-async/async/yield-loop-receives-events/middle.rs +++ b/tests/runtime-async/async/yield-loop-receives-events/middle.rs @@ -11,7 +11,7 @@ static mut HIT: bool = false; impl crate::exports::test::common::i_runner::Guest for Component { async fn f() { - wit_bindgen::spawn(async move { + wit_bindgen::spawn_local(async move { f().await; unsafe { HIT = true;