Esempio n. 1
0
 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();
     }
 }
Esempio n. 2
0
        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;
                }
            }
        }