public static Task Consume <T>(this Producer <T> producer, Action <T> consumer, ChannelOptions?options = null) => Consume(producer, t => { consumer(t); return(new ValueTask()); }, options);
public static Producer <TOut> Zip <TIn, TOther, TOut>(this Producer <TIn> producer, Producer <TOther> other, Func <TIn, TOther, TOut> action) { var actor = new TransformActor <TIn, TOut>(async(readerIn, writer, ct) => { using var consumer = new Consumer <TOther>(); other.LinkTo(consumer); await writer.WriteAsync( action( await readerIn.ReadAsync(ct), await consumer.ReadAsync(ct) ), ct ); }); return(actor.Outbox); }
public static Producer <T> RegulatePressure <T, TFeedback>(this Producer <T> producer, int limit, Producer <TFeedback> feedback, Func <int, int, TFeedback, int>?regulate = null, ChannelOptions?options = null) { regulate ??= (pressure, _2, _3) => pressure - 1; var actor = new PressureControlActor <T, TFeedback>(limit, regulate); producer.LinkTo(actor.Inbox, options); feedback.LinkTo(actor.Feedback, options); actor.Start(); return(actor.Outbox); }
public static Producer <T> Tap <T>(this Producer <T> producer, Action <Producer <T> > action) { action(producer); return(producer); }