Skip to main content

Module async_runtime

Module async_runtime 

Source
Expand description

Asynchronous task execution utilities.

This module provides a mechanism to spawn tasks asynchronously and wait for their completion.

It abstracts away the underlying implementation details, allowing for different task execution strategies based on the target architecture and features enabled.

§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));
}));
handle.await.expect("Task should complete successfully");
println!("Task completed");

Traits§

AbortableTask
A future that represents a running task which can be cancelled.
AsyncRuntime
An asynchronous runtime.

Functions§

get_async_runtime
Returns an AsyncRuntime to enable running operations which need to interact with an asynchronous runtime.
set_async_runtime
Sets the current AsyncRuntime to enable running operations which need to interact with an asynchronous runtime.

Type Aliases§

SpawnedTask
A pinned, boxed AbortableTask.
TaskFuture
A TaskFuture is a boxed future that represents a task that can be spawned and executed asynchronously.