RunBlockingAsync
Owns a safe callback and executes it after bounded blocking admission.
Module std.task
import std.task;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
RunBlockingAsync
pub async fn RunBlockingAsync<T>(Work: fn() -> T, Token: CancellationToken) -> Task<Result<T, TaskDispatchError>>
where T: MovableOwns a safe callback and executes it after bounded blocking admission. Work: Owned callable retained through suspension; invoked at most once. Token: Owned cancellation observation, inert by default. Return: Unique task containing the exact callback result or typed admission/cancellation error. Warning: Borrowed captures retain their original backing requirements. Cancellation is cooperative and cannot interrupt an already-running synchronous callback. The caller resumes on its own captured executor; this wrapper owns its selected route. T: Exact admitted Movable completion value.
Example
module example.runblockingasync;
from std.task import Task, RunBlockingAsync, CancellationSource;
fn Answer() -> i32 { return 42; }
fn NoWork() -> void {}
struct Producer { pub readonly fn Invoke() -> i32 { return 42; } }
struct Action { pub readonly fn Invoke() -> void {} }
async fn Main() -> Task<i32> {
switch await RunBlockingAsync(Answer) { case .Ok { Value = Value } => { if Value != 42 { return 1; } } case .Err => return 2; }
switch await RunBlockingAsync(NoWork) { case .Ok => {} case .Err => return 3; }
switch await RunBlockingAsync<i32>(default(Producer)) { case .Ok { Value = Value } => { if Value != 42 { return 4; } } case .Err => return 5; }
switch await RunBlockingAsync(default(Action)) { case .Ok => {} case .Err => return 6; }
var Source = {
// Keep writable result storage through the explicit noncopy payload transfer.
var SourceCreation = CancellationSource.TryCreate();
switch SourceCreation {
case .Ok { Value = Value: mut CancellationSource& } => break move(Value);
case .Err => return 7;
}
};
Source.RequestCancellation();
switch await RunBlockingAsync(Answer, Source.Token) { case .Ok => return 8; case .Err { Error = Error } => { if !(Error is .Cancelled) { return 9; } } }
return 0;
}RunBlockingAsync
pub fn RunBlockingAsync<T>(mut Work: fn() -> T) -> Task<Result<T, TaskDispatchError>>
where T: MovableSupplies the omitted arguments to RunBlockingAsync. Note: Defaults: Token = CancellationToken(). T: Same generic argument and constraints as the full operation. Work: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.
RunBlockingAsync
pub async fn RunBlockingAsync(Work: fn() -> void, Token: CancellationToken) -> Task<Result<void, TaskDispatchError>>Owns a safe callback and executes it after bounded blocking admission. Work: Owned callable retained through suspension; invoked at most once. Token: Owned cancellation observation, inert by default. Return: Unique task containing the exact callback result or typed admission/cancellation error. Warning: Borrowed captures retain their original backing requirements. Cancellation is cooperative and cannot interrupt an already-running synchronous callback. The caller resumes on its own captured executor; this wrapper owns its selected route.
RunBlockingAsync
pub fn RunBlockingAsync(mut Work: fn() -> void) -> Task<Result<void, TaskDispatchError>>Supplies the omitted arguments to RunBlockingAsync. Note: Defaults: Token = CancellationToken(). Work: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.
RunBlockingAsync
pub async fn RunBlockingAsync<T, C>(Work: C, Token: CancellationToken) -> Task<Result<T, TaskDispatchError>>
where T: Movable where C: Movable, NullaryCallable<T>Owns a safe callback and executes it after bounded blocking admission. Work: Owned callable retained through suspension; invoked at most once. Token: Owned cancellation observation, inert by default. Return: Unique task containing the exact callback result or typed admission/cancellation error. Warning: Borrowed captures retain their original backing requirements. Cancellation is cooperative and cannot interrupt an already-running synchronous callback. The caller resumes on its own captured executor; this wrapper owns its selected route. T: Exact Movable result. C: Owned safe readonly concrete callable.
RunBlockingAsync
pub fn RunBlockingAsync<T, C>(mut Work: C) -> Task<Result<T, TaskDispatchError>>
where T: Movable where C: Movable, NullaryCallable<T>Supplies the omitted arguments to RunBlockingAsync. Note: Defaults: Token = CancellationToken(). T: Same generic argument and constraints as the full operation. C: Same generic argument and constraints as the full operation. Work: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.
RunBlockingAsync
pub async fn RunBlockingAsync<C>(Work: C, Token: CancellationToken) -> Task<Result<void, TaskDispatchError>>
where C: Movable, NullaryCallable<void>Owns a safe callback and executes it after bounded blocking admission. Work: Owned callable retained through suspension; invoked at most once. Token: Owned cancellation observation, inert by default. Return: Unique task containing the exact callback result or typed admission/cancellation error. Warning: Borrowed captures retain their original backing requirements. Cancellation is cooperative and cannot interrupt an already-running synchronous callback. The caller resumes on its own captured executor; this wrapper owns its selected route. C: Owned safe readonly concrete callable with void result.
RunBlockingAsync
pub fn RunBlockingAsync<C>(mut Work: C) -> Task<Result<void, TaskDispatchError>>
where C: Movable, NullaryCallable<void>Supplies the omitted arguments to RunBlockingAsync. Note: Defaults: Token = CancellationToken(). C: Same generic argument and constraints as the full operation. Work: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.