Show / Hide Table of Contents

Class AsyncMulticastSequence<T>

Represents asynchronous broadcast channel for single producer and multiple consumer scenario.

Inheritance
object
AsyncMulticastSequence<T>
Implements
IAsyncEnumerable<T>
Inherited Members
object.GetType()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public sealed class AsyncMulticastSequence<T> : IAsyncEnumerable<T>
Type Parameters
Name Description
T

The type of the elements in the sequence.

Remarks

The subscription can be created by calling GetAsyncEnumerator(CancellationToken) method.

Constructors

View Source

AsyncMulticastSequence()

Declaration
public AsyncMulticastSequence()

Properties

View Source

IsCompleted

Gets a value indicating that this sequence is completed.

Declaration
public bool IsCompleted { get; }
Property Value
Type Description
bool
View Source

NotifyListenersSequentially

Gets or sets a value indicating how the consumer gets notified about a new value.

Declaration
public bool NotifyListenersSequentially { get; init; }
Property Value
Type Description
bool

true means that call to Current property doesn't signal the producer about consumption. The confirmation is produced by the next call to MoveNextAsync() method; false means that call to Current property signal the producer about consumption, and the producer can emit a new value without waiting for the next call to MoveNextAsync() method.

Methods

View Source

TryComplete(Exception?)

Tries to complete the sequence and notify all listeners.

Declaration
public bool TryComplete(Exception? e = null)
Parameters
Type Name Description
Exception e

The exception to broadcast to all listeners.

Returns
Type Description
bool

true if this sequence is completed successfully; false if this sequence is already completed.

View Source

WriteAsync(T, CancellationToken)

Sends the value to all attached listeners.

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

The value to produce.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<int>

A number of notified listeners.

Remarks

This method ensures that all consumers process the supplied value.

Implements

IAsyncEnumerable<T>

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)

See Also

ForEach<T>(IAsyncEnumerable<T>, Func<T, CancellationToken, ValueTask>, CancellationToken)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾