pub fn set_async_runtime(runtime: Arc<dyn AsyncRuntime>) -> Result<(), Error>Expand description
Sets the current AsyncRuntime to enable running operations which need to interact with an
asynchronous runtime.
§Arguments
runtime- An instance of a type that implements theAsyncRuntimetrait.
§Returns
Ok if the async runtime was set successfully, or an error if it has already been set.
§Examples
use typespec_client_core::async_runtime::{
set_async_runtime, AbortableTask, AsyncRuntime, TaskFuture, SpawnedTask};
use std::sync::Arc;
struct CustomRuntime;
impl AsyncRuntime for CustomRuntime {
fn spawn(&self, _f: TaskFuture) -> SpawnedTask {
unimplemented!("Custom spawn not implemented");
}
fn sleep(&self, _duration: typespec_client_core::time::Duration) -> TaskFuture {
unimplemented!("Custom sleep not implemented");
}
fn yield_now(&self) -> TaskFuture {
unimplemented!("Custom yield not implemented");
}
}
set_async_runtime(Arc::new(CustomRuntime)).expect("Failed to set async runtime");