void StartIterate() { if (enumerator == null) { if (iteratingState == IteratingState.IteratingFirst) { enumerator = first.GetAsyncEnumerator(cancellationToken); } else if (iteratingState == IteratingState.IteratingSecond) { enumerator = second.GetAsyncEnumerator(cancellationToken); } } try { awaiter = enumerator.MoveNextAsync().GetAwaiter(); } catch (Exception ex) { completionSource.TrySetException(ex); return; } if (awaiter.IsCompleted) { MoveNextCoreDelegate(this); } else { awaiter.SourceOnCompleted(MoveNextCoreDelegate, this); } }
public UniTask <bool> MoveNextAsync() { cancellationToken.ThrowIfCancellationRequested(); completionSource.Reset(); bool isCompleted = false; try { if (enumerator == null) { enumerator = source.GetAsyncEnumerator(cancellationToken); } awaiter = enumerator.MoveNextAsync().GetAwaiter(); isCompleted = awaiter.IsCompleted; } catch (Exception ex) { CallTrySetExceptionAfterNotification(ex); return(new UniTask <bool>(this, completionSource.Version)); } if (isCompleted) { MoveNextCore(this); } else { awaiter.SourceOnCompleted(MoveNextCoreDelegate, this); } return(new UniTask <bool>(this, completionSource.Version)); }
public UniTask <bool> MoveNextAsync() { if (cancellationToken1.IsCancellationRequested) { isCanceled = true; } if (cancellationToken2.IsCancellationRequested) { isCanceled = true; } if (enumerator == null) { enumerator = source.GetAsyncEnumerator(cancellationToken2); // use only AsyncEnumerator provided token. } if (isCanceled) { return(CompletedTasks.False); } completionSource.Reset(); SourceMoveNext(); return(new UniTask <bool>(this, completionSource.Version)); }
public UniTask <bool> MoveNextAsync() { cancellationToken.ThrowIfCancellationRequested(); completionSource.Reset(); if (enumerator == null) { if (state == State.RequireAppend) { Current = element; state = State.None; return(CompletedTasks.True); } enumerator = source.GetAsyncEnumerator(cancellationToken); } if (state == State.Completed) { return(CompletedTasks.False); } awaiter = enumerator.MoveNextAsync().GetAwaiter(); if (awaiter.IsCompleted) { MoveNextCoreDelegate(this); } else { awaiter.SourceOnCompleted(MoveNextCoreDelegate, this); } return(new UniTask <bool>(this, completionSource.Version)); }
public UniTask <bool> MoveNextAsync() { if (enumerator == null) { enumerator = source.GetAsyncEnumerator(cancellationToken); } completionSource.Reset(); if (!OnFirstIteration()) { SourceMoveNext(); } return(new UniTask <bool>(this, completionSource.Version)); }
public UniTask <bool> MoveNextAsync() { cancellationToken.ThrowIfCancellationRequested(); if (enumerator == null) { enumerator = source.GetAsyncEnumerator(cancellationToken); queue = new Queue <TSource>(); } completionSource.Reset(); SourceMoveNext(); return(new UniTask <bool>(this, completionSource.Version)); }
async UniTaskVoid CreateLookup() { try { lookup = await inner.ToLookupAsync(innerKeySelector, comparer, cancellationToken); enumerator = outer.GetAsyncEnumerator(cancellationToken); } catch (Exception ex) { completionSource.TrySetException(ex); return; } SourceMoveNext(); }
async UniTaskVoid RunSecondAfterDisposeAsync() { try { await enumerator.DisposeAsync(); enumerator = null; awaiter = default; iteratingState = IteratingState.IteratingSecond; } catch (Exception ex) { completionSource.TrySetException(ex); } StartIterate(); }
public UniTask <bool> MoveNextAsync() { cancellationToken.ThrowIfCancellationRequested(); if (sourceEnumerator == null) { sourceEnumerator = source.GetAsyncEnumerator(cancellationToken); channel = Channel.CreateSingleConsumerUnbounded <TSource>(); channelEnumerator = channel.Reader.ReadAllAsync().GetAsyncEnumerator(cancellationToken); ConsumeAll(this, sourceEnumerator, channel).Forget(); } return(channelEnumerator.MoveNextAsync()); }
async UniTaskVoid ConsumeEnumerator(IUniTaskAsyncEnumerable <T> source, CancellationToken cancellationToken) { enumerator = source.GetAsyncEnumerator(cancellationToken); try { while (await enumerator.MoveNextAsync()) { var value = enumerator.Current; this.latestValue = value; triggerEvent.SetResult(value); } } finally { await enumerator.DisposeAsync(); enumerator = null; } }
public IDisposable Connect() { if (connectedDisposable != null) { return(connectedDisposable); } if (enumerator == null) { enumerator = source.GetAsyncEnumerator(cancellationTokenSource.Token); } ConsumeEnumerator().Forget(); connectedDisposable = new ConnectDisposable(cancellationTokenSource); return(connectedDisposable); }
public UniTask <bool> MoveNextAsync() { cancellationToken.ThrowIfCancellationRequested(); if (enumerator == null) { enumerator = source.GetAsyncEnumerator(cancellationToken); } if (checked (index) >= count) { return(CompletedTasks.False); } completionSource.Reset(); SourceMoveNext(); return(new UniTask <bool>(this, completionSource.Version)); }
static async UniTaskVoid ConsumeAll(_Queue self, IUniTaskAsyncEnumerator <TSource> enumerator, ChannelWriter <TSource> writer) { try { while (await enumerator.MoveNextAsync()) { writer.TryWrite(enumerator.Current); } writer.TryComplete(); } catch (Exception ex) { writer.TryComplete(ex); } finally { self.channelClosed = true; await enumerator.DisposeAsync(); } }
internal static async UniTask <TSource[]> ToArrayAsync <TSource>(IUniTaskAsyncEnumerable <TSource> source, CancellationToken cancellationToken) { // UnityEngine.Debug.Log("Called ToArray"); var pool = ArrayPool <TSource> .Shared; var array = pool.Rent(16); TSource[] result = default; IUniTaskAsyncEnumerator <TSource> e = default; try { e = source.GetAsyncEnumerator(cancellationToken); var i = 0; while (await e.MoveNextAsync()) { ArrayPoolUtil.EnsureCapacity(ref array, i, pool); array[i++] = e.Current; } if (i == 0) { result = Array.Empty <TSource>(); } else { result = new TSource[i]; Array.Copy(array, result, i); } } finally { pool.Return(array, clearArray: !RuntimeHelpersAbstraction.IsWellKnownNoReferenceContainsType <TSource>()); if (e != null) { await e.DisposeAsync(); } } return(result); }
public UniTask <bool> MoveNextAsync() { completionSource.Reset(); // iterate selected field if (selectedEnumerator != null) { MoveNextSelected(); } else { // iterate source field if (sourceEnumerator == null) { sourceEnumerator = source.GetAsyncEnumerator(cancellationToken); } MoveNextSource(); } return(new UniTask <bool>(this, completionSource.Version)); }
ToLookupAwaitWithCancellationAsync <TSource, TKey, TElement>(IUniTaskAsyncEnumerable <TSource> source, Func <TSource, CancellationToken, UniTask <TKey> > keySelector, Func <TSource, CancellationToken, UniTask <TElement> > elementSelector, IEqualityComparer <TKey> comparer, CancellationToken cancellationToken) { var pool = ArrayPool <TSource> .Shared; var array = pool.Rent(16); IUniTaskAsyncEnumerator <TSource> e = default; try { e = source.GetAsyncEnumerator(cancellationToken); var i = 0; while (await e.MoveNextAsync()) { ArrayPoolUtil.EnsureCapacity(ref array, i, pool); array[i++] = e.Current; } if (i == 0) { return(Lookup <TKey, TElement> .CreateEmpty()); } else { return(await Lookup <TKey, TElement> .CreateAsync(new ArraySegment <TSource>(array, 0, i), keySelector, elementSelector, comparer, cancellationToken)); } } finally { pool.Return(array, clearArray: !RuntimeHelpersAbstraction.IsWellKnownNoReferenceContainsType <TSource>()); if (e != null) { await e.DisposeAsync(); } } }
internal Enumerator(IUniTaskAsyncEnumerator <T> enumerator) { this.enumerator = enumerator; }
public Enumerator(IUniTaskAsyncEnumerator <T> enumerator) { this.enumerator = enumerator; }