Show / Hide Table of Contents

Class AsyncExchanger<T>

Represents a synchronization point at which two async flows can cooperate and swap elements within pairs.

Inheritance
Object
AsyncExchanger<T>
Implements
IAsyncDisposable
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncExchanger<T> : Disposable, IAsyncDisposable
Type Parameters
Name Description
T

The type of objects that may be exchanged.

Remarks

This type is useful to organize pipeline between consumer and producer.

Properties

| Improve this Doc View Source

IsTerminated

Gets a value indicating whether this exchange has been terminated.

Declaration
public bool IsTerminated { get; }
Property Value
Type Description
Boolean
Exceptions
Type Condition
ObjectDisposedException

The object has been disposed.

Methods

| Improve this Doc View Source

Dispose(Boolean)

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing
| Improve this Doc View Source

DisposeAsync()

Provides graceful shutdown of this instance.

Declaration
public ValueTask DisposeAsync()
Returns
Type Description
ValueTask

The task representing state of asynchronous graceful shutdown.

| Improve this Doc View Source

ExchangeAsync(T, CancellationToken)

Waits for another flow to arrive at this exchange point, then transfers the given object to it, receiving its object as return value.

Declaration
public ValueTask<T> ExchangeAsync(T value, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
T value

The object to exchange.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<T>

The object provided by another async flow.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The object has been disposed.

ExchangeTerminatedException

The exhange has been terminated.

| Improve this Doc View Source

ExchangeAsync(T, TimeSpan, CancellationToken)

Waits for another flow to arrive at this exchange point, then transfers the given object to it, receiving its object as return value.

Declaration
public ValueTask<T> ExchangeAsync(T value, TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
T value

The object to exchange.

TimeSpan timeout

The maximum time to wait.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<T>

The object provided by another async flow.

Exceptions
Type Condition
ArgumentOutOfRangeException

timeout is negative.

OperationCanceledException

The operation has been canceled or timed out.

ObjectDisposedException

The object has been disposed.

ExchangeTerminatedException

The exhange has been terminated.

| Improve this Doc View Source

Terminate(Exception)

Informs another participant that no more data will be exchanged with it.

Declaration
public void Terminate(Exception exception = null)
Parameters
Type Name Description
Exception exception

The optional exception indicating termination reason.

Exceptions
Type Condition
ObjectDisposedException

The object has been disposed.

InvalidOperationException

The exchange is already terminated.

| Improve this Doc View Source

TryExchange(ref T)

Attempts to transfer the object to another flow synchronously.

Declaration
public bool TryExchange(ref T value)
Parameters
Type Name Description
T value

The object to exchange.

Returns
Type Description
Boolean

true if another flow is ready for exchange; otherwise, false.

Remarks

value remains unchanged if return value is false.

Exceptions
Type Condition
ObjectDisposedException

The object has been disposed.

ExchangeTerminatedException

The exhange has been terminated.

Implements

System.IAsyncDisposable

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)
ObjectExtensions.As<T>(T)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX