/// <summary> /// Similar to (and calls) ConsumeFlow, but staunches the flow as soon as it returns false, then starts it again. /// This is a piping tool and should not be used directly by consumers. /// </summary> public static IAsyncEnumerator <bool> ConsumeFlowUntilFull <T>(this IFlowConsumer <T> c, IAsyncEnumerator <T> flow) { return(new AsyncEnumerator <bool>(async yield => { await c.ConsumeFlow(flow).UntilAsync(async b => { await yield.ReturnAsync(b); return b; }, yield); })); }
/// <summary> /// Similar to (and calls) ConsumeFlow, but staunches the flow as soon as it returns false, then starts it again. /// This is a piping tool and should not be used directly by consumers. /// </summary> public static async IAsyncEnumerable <bool> ConsumeFlowUntilFull <T>(this IFlowConsumer <T> c, IAsyncEnumerable <T> flow) { await foreach (var b in c.ConsumeFlow(flow)) { yield return(b); if (!b) { yield break; } } }
/// <summary> /// Similar to (and calls) ConsumeFlow, but staunches the flow as soon as a certain droplet is found in the input flow, then starts it again. /// This is a piping tool and should not be used directly by consumers. /// </summary> public static async IAsyncEnumerable <bool> ConsumeFlowUntilDroplet <T>(this IFlowConsumer <T> c, IFlowProducer <T> producer, IAsyncEnumerable <T> flow, Predicate <T> stopOn) { if (producer.IsFlowStarted && producer is FlowProducerBase <T> prodImpl) { await foreach (var t in c.ConsumeFlow(Inner())) { yield return(t); } } async IAsyncEnumerable <T> Inner() { await foreach (var d in flow) { if (stopOn(d)) { yield break; } yield return(d); } } }
/// <summary> /// Similar to (and calls) ConsumeFlow, but staunches the flow as soon as a predicate running on the consumer itself matches, then starts it again. /// This is a piping tool and should not be used directly by consumers. /// </summary> public static async IAsyncEnumerable <bool> ConsumeFlowUntil <T>(this IFlowConsumer <T> c, IFlowProducer <T> producer, IAsyncEnumerable <T> flow, Func <bool> stop) { if (producer.IsFlowStarted && producer is FlowProducerBase <T> prodImpl) { await foreach (var b in c.ConsumeFlow(Inner())) { yield return(b); } } async IAsyncEnumerable <T> Inner() { await foreach (var d in flow) { if (stop()) { yield break; } yield return(d); } } }
/// <summary> /// Similar to (and calls) ConsumeFlow, but staunches the flow as soon as a certain droplet is found in the input flow, then starts it again. /// This is a piping tool and should not be used directly by consumers. /// </summary> public static IAsyncEnumerator <bool> ConsumeFlowUntilDroplet <T>(this IFlowConsumer <T> c, IFlowProducer <T> producer, IAsyncEnumerator <T> flow, Predicate <T> stopOn) { return(new AsyncEnumerator <bool>(async yield => { if (producer.IsFlowStarted && producer is FlowProducerBase <T> prodImpl) { await c.ConsumeFlow(new AsyncEnumerator <T>(async innerYield => { await flow.ForEachAsync(async d => { if (stopOn(d)) { innerYield.Break(); } await innerYield.ReturnAsync(d); }); })).UntilAsync(async b => { await yield.ReturnAsync(b); return b; }, yield); } })); }
public FlowFilter(Predicate <T[]> filter, int chunkSize, IFlowConsumer <T> filterConsumer = null) : base(FilterToMap(filter), chunkSize) { FilterSink = filterConsumer; }