Class AsyncMulticastSequence<T>
Represents asynchronous broadcast channel for single producer and multiple consumer scenario.
Implements
Inherited Members
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 SourceAsyncMulticastSequence()
Declaration
public AsyncMulticastSequence()
Properties
View SourceIsCompleted
Gets a value indicating that this sequence is completed.
Declaration
public bool IsCompleted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
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 SourceTryComplete(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. |
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.