public override V Complete() { if (!done) { queue.ReleaseRead(0); return(eofResult); } else { throw new InvalidOperationException("Get EOF: Complete or Cancel can be called only once"); } }
public override V Complete() { if (!done) { queue.ReleaseRead(1); return(convertResult(value)); } else { throw new InvalidOperationException("Get: Complete or Cancel can be called only once"); } }
public static async Task <Option <T> > Dequeue <T>(this IQueueSource <T> queue, CancellationToken ctoken) { AcquireReadResult result = await queue.AcquireReadAsync(1, ctoken); return(result.Visit <Option <T> > ( new Func <AcquireReadSucceeded, Option <T> > ( succeeded => { if (succeeded.ItemCount == 0) { return new None <T>(); } else { System.Diagnostics.Debug.Assert(succeeded.ItemCount == 1); bool wasCancelled = false; if (ctoken.IsCancellationRequested) { wasCancelled = true; queue.ReleaseRead(0); } else { queue.ReleaseRead(1); } if (wasCancelled) { throw new OperationCanceledException(ctoken); } return new Some <T>(((AcquireReadSucceeded <T>)succeeded).Items[0]); } } ), new Func <AcquireReadCancelled, Option <T> > ( cancelled => { throw new OperationCanceledException(ctoken); } ), new Func <AcquireReadFaulted, Option <T> > ( faulted => { throw faulted.Exception; } ) )); }
public void ReleaseRead(int consumedItems) { parent.ReleaseRead(consumedItems); }