示例#1
0
            async UniTaskVoid RunSecondAfterDisposeAsync()
            {
                try {
                    await enumerator.DisposeAsync();

                    enumerator     = null;
                    awaiter        = default;
                    iteratingState = IteratingState.IteratingSecond;
                }
                catch (Exception ex) {
                    completionSource.TrySetException(ex);
                }

                StartIterate();
            }
示例#2
0
 public UniTask DisposeAsync()
 {
     TaskTracker.RemoveTracking(this);
     if (enumerator != null)
     {
         return(enumerator.DisposeAsync());
     }
     return(default);
        public void Dispose()
        {
            if (enumerator != null)
            {
                enumerator.DisposeAsync().Forget();
            }

            triggerEvent.SetCompleted();
        }
示例#4
0
 public UniTask DisposeAsync()
 {
     TaskTracker.RemoveTracking(this);
     cancellationTokenRegistration1.Dispose();
     cancellationTokenRegistration2.Dispose();
     if (enumerator != null)
     {
         return(enumerator.DisposeAsync());
     }
     return(default);
示例#5
0
 public async UniTask DisposeAsync()
 {
     TaskTracker.RemoveTracking(this);
     if (selectedEnumerator != null)
     {
         await selectedEnumerator.DisposeAsync();
     }
     if (sourceEnumerator != null)
     {
         await sourceEnumerator.DisposeAsync();
     }
 }
示例#6
0
            public async UniTask DisposeAsync()
            {
                if (sourceEnumerator != null)
                {
                    await sourceEnumerator.DisposeAsync();
                }
                if (channelEnumerator != null)
                {
                    await channelEnumerator.DisposeAsync();
                }

                if (!channelClosed)
                {
                    channelClosed = true;
                    channel.Writer.TryComplete(new OperationCanceledException());
                }
            }
示例#7
0
        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;
            }
        }
            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();
                }
            }
示例#9
0
        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);
        }
示例#10
0
        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();
                }
            }
        }
 public UniTask DisposeAsync()
 {
     return(enumerator.DisposeAsync());
 }
示例#12
0
 public ValueTask DisposeAsync()
 {
     return(enumerator.DisposeAsync());
 }