Show / Hide Table of Contents

Class AsyncBridge

Allows to turn WaitHandle and CancellationToken into task.

Inheritance
object
AsyncBridge
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public static class AsyncBridge

Properties

| Edit this page View Source

MaxPoolSize

Gets or sets the capacity of the internal pool used to create awaitable tasks returned from the public methods in this class.

Declaration
public static int MaxPoolSize { get; set; }
Property Value
Type Description
int

Methods

| Edit this page View Source

AsCancellationToken(Task)

Returns a cancellation token that gets signaled when the task completes.

Declaration
public static CancellationToken AsCancellationToken(this Task task)
Parameters
Type Name Description
Task task

The task to observe.

Returns
Type Description
CancellationToken

The token that represents completion state of the task.

Exceptions
Type Condition
ArgumentNullException

task is null.

| Edit this page View Source

AsCancellationToken(Task, out Func<bool>)

Returns a cancellation token that gets signaled when the task completes.

Declaration
public static CancellationToken AsCancellationToken(this Task task, out Func<bool> disposeTokenSource)
Parameters
Type Name Description
Task task

The task to observe.

Func<bool> disposeTokenSource

A delegate that can be used to destroy the source of the returned token if no longer needed. It returns true if token was not canceled by the task; otherwise, false.

Returns
Type Description
CancellationToken

The token that represents completion state of the task.

Exceptions
Type Condition
ArgumentNullException

task is null.

| Edit this page View Source

WaitAnyAsync(ReadOnlySpan<CancellationToken>)

Creates a task that will complete when any of the supplied tokens have canceled.

Declaration
public static Task<CancellationToken> WaitAnyAsync(this ReadOnlySpan<CancellationToken> tokens)
Parameters
Type Name Description
ReadOnlySpan<CancellationToken> tokens

The tokens to wait on for cancellation.

Returns
Type Description
Task<CancellationToken>

The canceled token.

Exceptions
Type Condition
InvalidOperationException

tokens is empty.

| Edit this page View Source

WaitAnyAsync(ReadOnlySpan<CancellationToken>, out Func<object?, bool>)

Creates a task that will complete when any of the supplied tokens have canceled.

Declaration
public static Task<CancellationToken> WaitAnyAsync(this ReadOnlySpan<CancellationToken> tokens, out Func<object?, bool> interruption)
Parameters
Type Name Description
ReadOnlySpan<CancellationToken> tokens

The tokens to wait on for cancellation.

Func<object, bool> interruption

An interruption procedure than can be used to turn the returned task into the failed state.

Returns
Type Description
Task<CancellationToken>

The canceled token.

Exceptions
Type Condition
InvalidOperationException

tokens is empty.

PendingTaskInterruptedException

The returned task is interrupted by interruption procedure.

| Edit this page View Source

WaitAsync(CancellationToken, bool)

Obtains a task that can be used to await token cancellation.

Declaration
public static ValueTask WaitAsync(this CancellationToken token, bool completeAsCanceled = false)
Parameters
Type Name Description
CancellationToken token

The token to be converted into task.

bool completeAsCanceled

true to complete task in Canceled state; false to complete task in RanToCompletion state.

Returns
Type Description
ValueTask

A task representing token state.

Exceptions
Type Condition
ArgumentException

token doesn't support cancellation.

| Edit this page View Source

WaitAsync(WaitHandle, CancellationToken)

Obtains a task that can be used to await handle completion.

Declaration
public static ValueTask WaitAsync(this WaitHandle handle, CancellationToken token = default)
Parameters
Type Name Description
WaitHandle handle

The handle to await.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task that will be completed .

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

WaitAsync(WaitHandle, TimeSpan, CancellationToken)

Obtains a task that can be used to await handle completion.

Declaration
public static ValueTask<bool> WaitAsync(this WaitHandle handle, TimeSpan timeout, CancellationToken token = default)
Parameters
Type Name Description
WaitHandle handle

The handle to await.

TimeSpan timeout

The timeout used to await completion.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<bool>

true if handle is signaled; otherwise, false if timeout occurred.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾