pub trait AsyncRuntime: Send + Sync {
// Required methods
fn spawn_async_call(
&self,
callee: Value,
args: Vec<Value>,
env: Env,
) -> Value;
fn chan_take_blocking(&self, chan: Value) -> EvalResult;
fn chan_put_blocking(&self, chan: Value, val: Value) -> EvalResult<()>;
// Provided methods
fn spawn_fiber_call(
&self,
callee: Value,
args: Vec<Value>,
env: Env,
) -> EvalResult { ... }
fn take_if_channel(&self, val: &Value) -> Option<EvalResult> { ... }
}Expand description
Interface implemented by cljrs-async and registered with GlobalEnv.
All methods are called from the LocalSet thread, so Value / Env need
not be Send. The trait itself must be Send + Sync so the
Arc<dyn AsyncRuntime> inside GlobalEnv can be shared.
Required Methods§
Sourcefn spawn_async_call(&self, callee: Value, args: Vec<Value>, env: Env) -> Value
fn spawn_async_call(&self, callee: Value, args: Vec<Value>, env: Env) -> Value
Spawn a call to an ^:async function as a LocalSet task.
callee is the Value::Fn being invoked, args are the already-
evaluated arguments, env is the calling environment. Returns a
Value::Future immediately; the body runs concurrently.
Sourcefn chan_take_blocking(&self, chan: Value) -> EvalResult
fn chan_take_blocking(&self, chan: Value) -> EvalResult
Block the current OS thread until a value can be taken from the channel.
Used by the IR interpreter’s sync-context fallback for ChanTake.
Returns Value::Nil on a closed channel.
Sourcefn chan_put_blocking(&self, chan: Value, val: Value) -> EvalResult<()>
fn chan_put_blocking(&self, chan: Value, val: Value) -> EvalResult<()>
Block the current OS thread until the value is accepted by the channel.
Used by the IR interpreter’s sync-context fallback for ChanPut.
Provided Methods§
Sourcefn spawn_fiber_call(
&self,
callee: Value,
args: Vec<Value>,
env: Env,
) -> EvalResult
fn spawn_fiber_call( &self, callee: Value, args: Vec<Value>, env: Env, ) -> EvalResult
Spawn an ordinary synchronous call on a parking-capable fiber. Runtimes without fibers retain their async task implementation.
Sourcefn take_if_channel(&self, val: &Value) -> Option<EvalResult>
fn take_if_channel(&self, val: &Value) -> Option<EvalResult>
await support: if val is one of this runtime’s channels, take from it,
parking the calling fiber (or blocking the OS thread outside a fiber),
and keep it rooted for the whole wait. On wasm32, which cannot park, a
ready value (or nil for a closed channel) is returned at once and a take
that would block is an error. Returns None for any other value.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".