get_async_runtime

Function get_async_runtime 

Source
pub fn get_async_runtime() -> Arc<dyn AsyncRuntime>
Expand description

Returns an AsyncRuntime to enable running operations which need to interact with an asynchronous runtime.

The implementation depends on the target architecture and the features enabled:

  • If the tokio feature is enabled, it uses a tokio based spawner and timer.
  • If the tokio feature is not enabled and the target architecture is not wasm32, it uses a std::thread based spawner and timer.

§Returns

An instance of a AsyncRuntime which can be used to spawn background tasks or perform other asynchronous operations.

§Examples

use typespec_client_core::async_runtime::get_async_runtime;

let async_runtime = get_async_runtime();
let handle = async_runtime.spawn(Box::pin(async {
  // Simulate some work
  std::thread::sleep(std::time::Duration::from_secs(1));
}));