Show / Hide Table of Contents

Struct CancellationTokenMultiplexer

Represents cancellation token multiplexer.

Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public readonly struct CancellationTokenMultiplexer
Remarks

The multiplexer provides a pool of CancellationTokenSource to combine the cancellation tokens.

Constructors

View Source

CancellationTokenMultiplexer()

Represents cancellation token multiplexer.

Declaration
public CancellationTokenMultiplexer()
Remarks

The multiplexer provides a pool of CancellationTokenSource to combine the cancellation tokens.

Properties

View Source

MaximumRetained

Gets or sets the maximum retained CancellationTokenSource instances.

Declaration
public int MaximumRetained { get; init; }
Property Value
Type Description
int

The maximum CancellationTokenSource instances in the internal pool; or MaxValue to use unbounded pool.

Methods

View Source

Combine(params ReadOnlySpan<CancellationToken>)

Combines the multiple tokens.

Declaration
public CancellationTokenMultiplexer.Scope Combine(params ReadOnlySpan<CancellationToken> tokens)
Parameters
Type Name Description
ReadOnlySpan<CancellationToken> tokens

The tokens to be combined.

Returns
Type Description
CancellationTokenMultiplexer.Scope

The scope that contains a single multiplexed token.

View Source

Combine(TimeSpan, params ReadOnlySpan<CancellationToken>)

Combines the multiple tokens and the timeout.

Declaration
public CancellationTokenMultiplexer.Scope Combine(TimeSpan timeout, params ReadOnlySpan<CancellationToken> tokens)
Parameters
Type Name Description
TimeSpan timeout

The timeout that could trigger the cancellation.

ReadOnlySpan<CancellationToken> tokens

The tokens to be combined.

Returns
Type Description
CancellationTokenMultiplexer.Scope

The scope that represents the multiplexed token.

Remarks

The cancellation triggered by the timeout can be detected by checking IsTimedOut.

Exceptions
Type Condition
ArgumentOutOfRangeException

timeout is negative or too large.

View Source

CombineAndSetTimeoutLater(params ReadOnlySpan<CancellationToken>)

Combines the multiple tokens and sets the timeout later.

Declaration
public CancellationTokenMultiplexer.ScopeWithTimeout CombineAndSetTimeoutLater(params ReadOnlySpan<CancellationToken> tokens)
Parameters
Type Name Description
ReadOnlySpan<CancellationToken> tokens

The tokens to be combined.

Returns
Type Description
CancellationTokenMultiplexer.ScopeWithTimeout

The scope that represents the multiplexed token.

View Source

WaitAnyAsync(params ReadOnlySpan<CancellationToken>)

Waits for the cancellation of at least one provided token.

Declaration
public ValueTask<CancellationToken> WaitAnyAsync(params ReadOnlySpan<CancellationToken> tokens)
Parameters
Type Name Description
ReadOnlySpan<CancellationToken> tokens

A set of tokens.

Returns
Type Description
ValueTask<CancellationToken>

The first canceled token.

Exceptions
Type Condition
ArgumentOutOfRangeException

tokens is empty.

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾