Ejemplo n.º 1
0
 internal AsyncLookup(
     IAsyncEnumerable <TSource> source,
     Func <TSource, Task <TKey> > keySelector,
     Func <TSource, Task <TElement> > elementSelector,
     IEqualityComparer <TKey> keyComparer)
 {
     _keySelector     = keySelector;
     _elementSelector = elementSelector;
     _iterator        = source.GetAsyncEnumerator();
     _factory         = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(1));
     _dictionary      = new ConcurrentDictionary <TKey, AsyncGrouping <TKey, TElement> >(keyComparer);
     _completed       = new TaskCompletionSource <bool>();
     _inProgress      = new PartialAsyncCollection <AsyncGrouping <TKey, TElement> >(MoveNextUntied);
 }
Ejemplo n.º 2
0
        private async Task CompleteIteration()
        {
            //Should only be called by MoveNextInternal
            Debug.Assert(_inProgress != null);
            foreach (var grouping in _dictionary.Values)
            {
                await grouping.MarkComplete();
            }
            await _inProgress.CompleteAdding();

            _completed.TrySetResult(true);
            _inProgress = null;
            //Clear out other items we'll no longer need
            _keySelector     = null;
            _elementSelector = null;
            _iterator        = null;
        }