Skip to content

Commit 56c89e6

Browse files
committed
Add futures-util and use their now_or_never
1 parent 21830cd commit 56c89e6

6 files changed

Lines changed: 10 additions & 35 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ fs_extra = "1.3.0"
182182
fs2 = "0.4.3"
183183
futures = "0.3"
184184
futures-channel = "0.3"
185+
futures-util = "0.3"
185186
getrandom02 = { package = "getrandom", version = "0.2" }
186187
glob = "0.3.1"
187188
hashbrown = { version = "0.15", default-features = false, features = ["equivalent", "inline-more"] }

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum-map.workspace = true
5858
flate2.workspace = true
5959
fs2.workspace = true
6060
futures.workspace = true
61+
futures-util.workspace = true
6162
hashbrown = { workspace = true, features = ["rayon", "serde"] }
6263
hex.workspace = true
6364
hostname.workspace = true

crates/core/src/host/wasmtime/wasmtime_module.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::energy::ReducerBudget;
66
use crate::host::instance_env::InstanceEnv;
77
use crate::host::wasm_common::module_host_actor::{DescribeError, InitializationError};
88
use crate::host::wasm_common::*;
9-
use crate::util::poll_once_executor::poll_once;
109
use crate::util::string_from_utf8_lossy_owned;
10+
use futures_util::FutureExt;
1111
use spacetimedb_primitives::errno::HOST_CALL_FAILURE;
1212
use wasmtime::{
1313
AsContext, AsContextMut, ExternType, Instance, InstancePre, Linker, Store, TypedFunc, WasmBacktrace, WasmParams,
@@ -94,15 +94,16 @@ const CALL_FAILURE: i32 = HOST_CALL_FAILURE.get() as i32;
9494
/// Our Wasmtime is configured for `async` execution, and will panic if we use the non-async [`TypedFunc::call`].
9595
/// The `async` config is necessary to allow procedures to suspend, e.g. when making HTTP calls or acquiring transactions.
9696
/// However, most of the WASM we execute, incl. reducers and startup functions, should never block/yield.
97-
/// Rather than crossing our fingers and trusting, we run [`TypedFunc::call_async`] in [`crate::util::poll_once_executor`],
98-
/// a custom "async executor" which invokes [`std::task::Future::poll`] exactly once.
97+
/// Rather than crossing our fingers and trusting, we run [`TypedFunc::call_async`] in [`FutureExt::now_or_never`],
98+
/// an "async executor" which invokes [`std::task::Future::poll`] exactly once.
9999
fn call_sync_typed_func<Args: WasmParams, Ret: WasmResults>(
100100
typed_func: &TypedFunc<Args, Ret>,
101101
store: &mut Store<WasmInstanceEnv>,
102102
args: Args,
103103
) -> anyhow::Result<Ret> {
104104
let fut = typed_func.call_async(store, args);
105-
poll_once(fut).expect("`call_async` of supposedly synchronous WASM function returned `Poll::Pending`")
105+
fut.now_or_never()
106+
.expect("`call_async` of supposedly synchronous WASM function returned `Poll::Pending`")
106107
}
107108

108109
impl module_host_actor::WasmInstancePre for WasmtimeModule {
@@ -113,7 +114,8 @@ impl module_host_actor::WasmInstancePre for WasmtimeModule {
113114
let mut store = Store::new(self.module.module().engine(), env);
114115
let instance_fut = self.module.instantiate_async(&mut store);
115116

116-
let instance = poll_once(instance_fut)
117+
let instance = instance_fut
118+
.now_or_never()
117119
.expect("`instantiate_async` did not immediately return `Ready`")
118120
.map_err(InitializationError::Instantiation)?;
119121

crates/core/src/util/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub mod prometheus_handle;
99
pub mod jobs;
1010
pub mod notify_once;
1111
pub mod slow;
12-
pub mod poll_once_executor;
1312

1413
// TODO: use String::from_utf8_lossy_owned once stabilized
1514
pub(crate) fn string_from_utf8_lossy_owned(v: Vec<u8>) -> String {

crates/core/src/util/poll_once_executor.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)