DotNext.Threading by .NET Foundation and Contributors

<PackageReference Include="DotNext.Threading" Version="4.0.0-beta.5" />

 AsyncExchanger<T>

Represents a synchronization point at which two async flows can cooperate and swap elements within pairs.
public bool IsTerminated { get; }

Gets a value indicating whether this exchange has been terminated.

public AsyncExchanger()

Initializes a new asynchronous exchanger.

Provides graceful shutdown of this instance.

public ValueTask<T> ExchangeAsync(T value, TimeSpan timeout, CancellationToken token = default)

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

public ValueTask<T> ExchangeAsync(T value, CancellationToken token = default)

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

public void Terminate(Exception exception = null)

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

public bool TryExchange(ref T value)

Attempts to transfer the object to another flow synchronously.