using System.Runtime.CompilerServices;
using ZB.MOM.WW.MxGateway.Contracts.Proto;
namespace ZB.MOM.WW.MxGateway.Client;
///
/// Extension methods that project a raw stream into the
/// typed surface, making the gateway's
/// reconnect-replay gap sentinel observable.
///
public static class MxEventStreamExtensions
{
///
/// Projects a raw stream (e.g.
/// or
/// ) into typed
/// values. Normal events pass through with
/// false; the gateway's
/// reconnect-replay gap sentinel is surfaced with
/// true and
/// populated. The stream is
/// forwarded faithfully — no event is synthesized or dropped.
///
/// The raw event stream to wrap.
/// Cancellation token for the enumeration.
/// The same events, each wrapped as an .
public static async IAsyncEnumerable AsStreamItemsAsync(
this IAsyncEnumerable source,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(source);
await foreach (MxEvent gatewayEvent in source
.WithCancellation(cancellationToken)
.ConfigureAwait(false))
{
yield return MxEventStreamItem.From(gatewayEvent);
}
}
}