public override async Task Flush(FlowBuffer <TInput> inBuf, FlowBuffer <TOutput> outBuf) { if (outBuf is FlowBuffer <TInput> buf) { await buf.ConsumeFlow(inBuf.Flow()).Collect(); } else { await outBuf.ConsumeFlow(Map((await inBuf.Flow().Collect()).ToArray()).GetAsyncEnumerator()).Collect(); } }
public override async Task Update(FlowBuffer <TInput> inBuf, FlowBuffer <TOutput> outBuf) { TInput[] oldContents = inBuf.Contents.ToArray(); TOutput[] mapped = Map(oldContents); if (ConsumeIf(oldContents, mapped)) { await inBuf.Flow(maxDroplets : inBuf.Capacity).Collect(); mapped = OnInputTransformed(oldContents, mapped); await outBuf.ConsumeFlow(mapped.GetAsyncEnumerator()).Collect(); } else if (inBuf.Full) { switch (InputBufferStrategy) { default: case InputBufferFullStrategy.FlushToOutput: await inBuf.Drip(); await outBuf.ConsumeDroplet(mapped[0]); break; case InputBufferFullStrategy.Empty: while (!inBuf.Empty) { await inBuf.Drip(); } break; case InputBufferFullStrategy.Drip: await inBuf.Drip(); break; } } }
/// <summary> /// Called when the input flow is staunched and the machine still has contents in its input buffer. /// </summary> /// <param name="inBuf">The input buffer</param> /// <param name="outBuf">The output buffer</param> public abstract Task Flush(FlowBuffer <TInput> inBuf, FlowBuffer <TOutput> outBuf);
public override async Task Update(FlowBuffer <TInput> inBuf, FlowBuffer <TOutput> outBuf) { await outBuf.ConsumeDroplet(Map(await inBuf.Drip())); }
/// <summary> /// Called whenever a droplet is pushed into the input buffer. /// Pushing into the output buffer will signal the start of a chunk of data. /// </summary> /// <param name="inBuf">The input buffer</param> /// <param name="outBuf">The output buffer</param> public abstract Task Update(FlowBuffer <TInput> inBuf, FlowBuffer <TOutput> outBuf);