public async ValueTask <bool> MoveNextAsync() { for (; ;) { var d = _done; var success = _queue.TryDequeue(out var v); if (d && !success) { if (_error != null) { throw _error; } return(false); } if (success) { Current = v; return(true); } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var d = _done && Volatile.Read(ref _inners).Length == 0; var success = _queue.TryDequeue(out var v); if (d && !success) { if (_errors != null) { throw _errors; } return(false); } if (success) { if (v.HasValue) { Current = v.Value; v.Sender.ConsumedOne(); return(true); } Remove(v.Sender); NextSource(); continue; } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var d = _done; var v = Interlocked.Exchange(ref _latest, null); if (d && v == null) { if (_error != null) { throw _error; } return(false); } if (v != null) { Current = v.Value; return(true); } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public ValueTask DisposeAsync() { if (Interlocked.Increment(ref _disposeWip) == 1) { return(_source.DisposeAsync()); } return(ResumeHelper.Await(ref _disposeTask)); }
public async ValueTask Complete() { await ResumeHelper.Await(ref _consumed); ResumeHelper.Clear(ref _consumed); _done = true; ResumeHelper.Resume(ref _valueReady); }
public ValueTask DisposeAsync() { _cts.Cancel(); if (Interlocked.Increment(ref _disposeWip) == 1) { Interlocked.Exchange(ref _timerLatest, EmptyHelper.EmptyIndicator); return(_source.DisposeAsync()); } return(ResumeHelper.Await(ref _disposeTask)); }
public async ValueTask Next(TValue value) { await ResumeHelper.Await(ref _consumed); ResumeHelper.Clear(ref _consumed); _current = value; ResumeHelper.Resume(ref _valueReady); }
public async ValueTask Error(Exception ex) { await ResumeHelper.Await(ref _consumed); ResumeHelper.Clear(ref _consumed); _error = ex; _done = true; ResumeHelper.Resume(ref _valueReady); }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var d = _sourceDone; var v = _sourceReady; if (d) { var ex = _sourceError; if (ex != null) { throw ex; } if (!v) { return(false); } } d = _otherDone; var o = Volatile.Read(ref _otherValue); if (d) { var ex = _otherError; if (ex != null) { throw ex; } if (o == EmptyHelper.EmptyIndicator) { return(false); } } if (v) { _sourceReady = false; if (o == EmptyHelper.EmptyIndicator) { MoveNextMain(); continue; } Current = _func(_sourceValue, (TOther)o); MoveNextMain(); return(true); } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public ValueTask DisposeAsync() { CancellationHelper.Cancel(ref _cts); if (Interlocked.Increment(ref _disposeWip) == 1) { if (_emitLast) { _emitLastItem = default; } return(_source.DisposeAsync()); } return(ResumeHelper.Await(ref _disposeTask)); }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var d = _sourceDone; var curr = _currentInner; if (curr == null) { if (_inners.TryDequeue(out curr)) { _currentInner = curr; } } if (d && curr == null) { var ex = _error; if (ex != null) { _error = null; throw ex; } return(false); } if (curr != null) { d = curr.Done; var success = curr.Queue.TryDequeue(out var v); if (d && !success) { curr.Dispose(); _currentInner = null; SourceConsumedOne(); continue; } if (success) { Current = v; curr.ConsumedOne(); return(true); } } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var d = _done; var curr = Volatile.Read(ref _current); if (d && curr == null) { var ex = _error; if (ex != null) { _error = null; throw ex; } return(false); } if (curr != null) { d = curr.Done; if (curr.HasValue) { Current = curr.Value; curr.Value = default; curr.HasValue = false; if (curr == Volatile.Read(ref _current)) { curr.MoveNext(); } return(true); } if (d) { if (Interlocked.CompareExchange(ref _current, null, curr) == curr) { curr.Dispose(); } continue; } } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { await ResumeHelper.Await(ref _valueReady); ResumeHelper.Clear(ref _valueReady); if (_done) { if (_error != null) { throw _error; } return(false); } Current = _current; ResumeHelper.Resume(ref _consumed); return(true); }
public async ValueTask Next(T value) { if (_disposeRequested) { return; } await ResumeHelper.Await(ref _consumed); ResumeHelper.Clear(ref _consumed); if (_disposeRequested) { return; } Current = value; _hasValue = true; ResumeHelper.Resume(ref _valueReady); }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var d = _done; var success = _queue.TryDequeue(out var v); if (d && !success) { if (_error != null) { throw _error; } return(false); } if (success) { Current = v; var c = _consumed + 1; if (c == _limit) { _consumed = 0; if (Interlocked.Add(ref _outstanding, c) == c) { MoveNext(); } } else { _consumed = c; } return(true); } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
internal void SetTask(Task task) { _task = task.ContinueWith(async t => { if (_disposeRequested) { return; } await ResumeHelper.Await(ref _consumed); ResumeHelper.Clear(ref _consumed); if (_disposeRequested) { return; } _error = ExceptionHelper.Extract(t.Exception); ResumeHelper.Resume(ref _valueReady); }, Token); }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var ex = Volatile.Read(ref _error); if (ex != null && ex != ExceptionHelper.Terminated) { throw ex; } var d = Volatile.Read(ref _done); var e = Volatile.Read(ref _hasValue); if (d && !e) { return(false); } if (e) { _hasValue = false; var next = false; if (Volatile.Read(ref _gate) != 0) { next = true; Current = _source.Current; } MoveNextMain(); if (next) { return(true); } } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { if (!_once) { _once = true; foreach (var inner in _sources) { inner.MoveNext(); } } for (; ;) { var d = Volatile.Read(ref _done) == 0; var success = _queue.TryDequeue(out var v); if (d && !success) { var ex = _error; if (ex != null) { _error = null; throw ex; } return(false); } if (success) { Current = v.Value; v.Sender.MoveNext(); return(true); } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { ResumeHelper.Resume(ref _consumed); await ResumeHelper.Await(ref _valueReady); ResumeHelper.Clear(ref _valueReady); if (_hasValue) { _hasValue = false; return(true); } Current = default; var ex = _error; if (ex != null) { _error = null; throw ex; } return(false); }
public async ValueTask <bool> MoveNextAsync() { for (; ;) { var a = Volatile.Read(ref _available); var b = _index; if (a != b) { Current = b; _index = b + 1; return(true); } if (b == _end) { return(false); } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { if (_done) { var ex = ExceptionHelper.Terminate(ref _error); if (ex != null) { throw ex; } return(false); } for (; ;) { var success = _queue.TryDequeue(out var entry); if (success) { var b = _buffer; if (entry.Done) { _done = true; if (b != null) { Current = b; _buffer = default; return(true); } var ex = ExceptionHelper.Terminate(ref _error); if (ex != null) { throw ex; } return(false); } if (entry.Boundary) { if (b == null) { Current = _collectionSupplier(); } else { Current = b; _buffer = default; } _size = 0; MoveNextOther(); return(true); } if (b == null) { b = _collectionSupplier(); _buffer = b; } b.Add(entry.Value); if (++_size == _maxSize) { Current = b; _buffer = default; _size = 0; MoveNextSource(); return(true); } MoveNextSource(); continue; } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }
public async ValueTask <bool> MoveNextAsync() { if (!_once) { _once = true; MoveNextAll(); } var latest = _latest; var n = latest.Length; for (; ;) { if (_done == 0) { var ex = ExceptionHelper.Terminate(ref _error); if (ex != null) { throw ex; } return(false); } var success = _queue.TryDequeue(out var entry); if (success) { var inner = _sources[entry.Index]; if (entry.Done) { if (inner.HasLatest) { _done--; } else { _done = 0; } continue; } if (!inner.HasLatest) { inner.HasLatest = true; _latestRemaining--; } latest[entry.Index] = entry.Value; if (_latestRemaining == 0) { var copy = new TSource[n]; Array.Copy(latest, 0, copy, 0, n); Current = _combiner(copy); inner.MoveNext(); return(true); } inner.MoveNext(); continue; } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }