// this will be called FIRST in the use of the enumerator, so we can await the enumerator get task, the rest can use result safely public ValueTask <bool> MoveNextAsync() { if (CancellationToken.IsCancellationRequested) { return(new ValueTask <bool>(Task.FromCanceled <bool>(CancellationToken))); } return(new ValueTask <bool>(GetEnumerator.ContinueWith <bool>(x => x.Result.MoveNext()))); }
public object InvokeGetEnumerator(object instance) { try { return(GetEnumerator.Invoke(instance, null) !); } catch (TargetInvocationException exception) { throw new EnumerationException($"Unhandled exception in {GetEnumerator.DeclaringType!.Name}.GetEnumerator().", exception.InnerException !); } }
public virtual IEnumerator <TSource> GetEnumerator <TSource>(IObservable <TSource> source) { #if !NO_PERF && !NO_CDS var e = new GetEnumerator <TSource>(); return(e.Run(source)); #else var q = new Queue <Notification <TSource> >(); var s = new Semaphore(0, int.MaxValue); return(PushToPull( source, x => { lock (q) q.Enqueue(x); s.Release(); }, () => { s.WaitOne(); lock (q) return q.Dequeue(); })); #endif }
// this will be called FIRST in the use of the enumerator, so we can await the enumerator get task, the rest can use result safely public async Task <bool> MoveNext(CancellationToken cancellationToken) { return((await GetEnumerator.ConfigureAwait(false)).MoveNext()); }
public virtual IEnumerator <TSource> GetEnumerator <TSource>(IObservable <TSource> source) { var e = new GetEnumerator <TSource>(); return(e.Run(source)); }