123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- using Cysharp.Threading.Tasks.Internal;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- namespace Cysharp.Threading.Tasks.Linq
- {
- public static partial class UniTaskAsyncEnumerable
- {
- public static IUniTaskAsyncEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector)
- {
- Error.ThrowArgumentNullException(outer, nameof(outer));
- Error.ThrowArgumentNullException(inner, nameof(inner));
- Error.ThrowArgumentNullException(outerKeySelector, nameof(outerKeySelector));
- Error.ThrowArgumentNullException(innerKeySelector, nameof(innerKeySelector));
- Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
- return new GroupJoin<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, EqualityComparer<TKey>.Default);
- }
- public static IUniTaskAsyncEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
- {
- Error.ThrowArgumentNullException(outer, nameof(outer));
- Error.ThrowArgumentNullException(inner, nameof(inner));
- Error.ThrowArgumentNullException(outerKeySelector, nameof(outerKeySelector));
- Error.ThrowArgumentNullException(innerKeySelector, nameof(innerKeySelector));
- Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
- Error.ThrowArgumentNullException(comparer, nameof(comparer));
- return new GroupJoin<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
- }
- public static IUniTaskAsyncEnumerable<TResult> GroupJoinAwait<TOuter, TInner, TKey, TResult>(this IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector)
- {
- Error.ThrowArgumentNullException(outer, nameof(outer));
- Error.ThrowArgumentNullException(inner, nameof(inner));
- Error.ThrowArgumentNullException(outerKeySelector, nameof(outerKeySelector));
- Error.ThrowArgumentNullException(innerKeySelector, nameof(innerKeySelector));
- Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
- return new GroupJoinAwait<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, EqualityComparer<TKey>.Default);
- }
- public static IUniTaskAsyncEnumerable<TResult> GroupJoinAwait<TOuter, TInner, TKey, TResult>(this IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
- {
- Error.ThrowArgumentNullException(outer, nameof(outer));
- Error.ThrowArgumentNullException(inner, nameof(inner));
- Error.ThrowArgumentNullException(outerKeySelector, nameof(outerKeySelector));
- Error.ThrowArgumentNullException(innerKeySelector, nameof(innerKeySelector));
- Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
- Error.ThrowArgumentNullException(comparer, nameof(comparer));
- return new GroupJoinAwait<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
- }
- public static IUniTaskAsyncEnumerable<TResult> GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(this IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector)
- {
- Error.ThrowArgumentNullException(outer, nameof(outer));
- Error.ThrowArgumentNullException(inner, nameof(inner));
- Error.ThrowArgumentNullException(outerKeySelector, nameof(outerKeySelector));
- Error.ThrowArgumentNullException(innerKeySelector, nameof(innerKeySelector));
- Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
- return new GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, EqualityComparer<TKey>.Default);
- }
- public static IUniTaskAsyncEnumerable<TResult> GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(this IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
- {
- Error.ThrowArgumentNullException(outer, nameof(outer));
- Error.ThrowArgumentNullException(inner, nameof(inner));
- Error.ThrowArgumentNullException(outerKeySelector, nameof(outerKeySelector));
- Error.ThrowArgumentNullException(innerKeySelector, nameof(innerKeySelector));
- Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
- Error.ThrowArgumentNullException(comparer, nameof(comparer));
- return new GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
- }
- }
- internal sealed class GroupJoin<TOuter, TInner, TKey, TResult> : IUniTaskAsyncEnumerable<TResult>
- {
- readonly IUniTaskAsyncEnumerable<TOuter> outer;
- readonly IUniTaskAsyncEnumerable<TInner> inner;
- readonly Func<TOuter, TKey> outerKeySelector;
- readonly Func<TInner, TKey> innerKeySelector;
- readonly Func<TOuter, IEnumerable<TInner>, TResult> resultSelector;
- readonly IEqualityComparer<TKey> comparer;
- public GroupJoin(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
- {
- this.outer = outer;
- this.inner = inner;
- this.outerKeySelector = outerKeySelector;
- this.innerKeySelector = innerKeySelector;
- this.resultSelector = resultSelector;
- this.comparer = comparer;
- }
- public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
- {
- return new _GroupJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
- }
- sealed class _GroupJoin : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
- {
- static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
- readonly IUniTaskAsyncEnumerable<TOuter> outer;
- readonly IUniTaskAsyncEnumerable<TInner> inner;
- readonly Func<TOuter, TKey> outerKeySelector;
- readonly Func<TInner, TKey> innerKeySelector;
- readonly Func<TOuter, IEnumerable<TInner>, TResult> resultSelector;
- readonly IEqualityComparer<TKey> comparer;
- CancellationToken cancellationToken;
- ILookup<TKey, TInner> lookup;
- IUniTaskAsyncEnumerator<TOuter> enumerator;
- UniTask<bool>.Awaiter awaiter;
- public _GroupJoin(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- this.outer = outer;
- this.inner = inner;
- this.outerKeySelector = outerKeySelector;
- this.innerKeySelector = innerKeySelector;
- this.resultSelector = resultSelector;
- this.comparer = comparer;
- this.cancellationToken = cancellationToken;
- TaskTracker.TrackActiveTask(this, 3);
- }
- public TResult Current { get; private set; }
- public UniTask<bool> MoveNextAsync()
- {
- cancellationToken.ThrowIfCancellationRequested();
- completionSource.Reset();
- if (lookup == null)
- {
- CreateLookup().Forget();
- }
- else
- {
- 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();
- }
- void SourceMoveNext()
- {
- try
- {
- awaiter = enumerator.MoveNextAsync().GetAwaiter();
- if (awaiter.IsCompleted)
- {
- MoveNextCore(this);
- }
- else
- {
- awaiter.SourceOnCompleted(MoveNextCoreDelegate, this);
- }
- }
- catch (Exception ex)
- {
- completionSource.TrySetException(ex);
- }
- }
- static void MoveNextCore(object state)
- {
- var self = (_GroupJoin)state;
- if (self.TryGetResult(self.awaiter, out var result))
- {
- if (result)
- {
- var outer = self.enumerator.Current;
- var key = self.outerKeySelector(outer);
- var values = self.lookup[key];
- self.Current = self.resultSelector(outer, values);
- self.completionSource.TrySetResult(true);
- }
- else
- {
- self.completionSource.TrySetResult(false);
- }
- }
- }
- public UniTask DisposeAsync()
- {
- TaskTracker.RemoveTracking(this);
- if (enumerator != null)
- {
- return enumerator.DisposeAsync();
- }
- return default;
- }
- }
- }
- internal sealed class GroupJoinAwait<TOuter, TInner, TKey, TResult> : IUniTaskAsyncEnumerable<TResult>
- {
- readonly IUniTaskAsyncEnumerable<TOuter> outer;
- readonly IUniTaskAsyncEnumerable<TInner> inner;
- readonly Func<TOuter, UniTask<TKey>> outerKeySelector;
- readonly Func<TInner, UniTask<TKey>> innerKeySelector;
- readonly Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector;
- readonly IEqualityComparer<TKey> comparer;
- public GroupJoinAwait(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
- {
- this.outer = outer;
- this.inner = inner;
- this.outerKeySelector = outerKeySelector;
- this.innerKeySelector = innerKeySelector;
- this.resultSelector = resultSelector;
- this.comparer = comparer;
- }
- public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
- {
- return new _GroupJoinAwait(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
- }
- sealed class _GroupJoinAwait : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
- {
- static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
- readonly static Action<object> ResultSelectCoreDelegate = ResultSelectCore;
- readonly static Action<object> OuterKeySelectCoreDelegate = OuterKeySelectCore;
- readonly IUniTaskAsyncEnumerable<TOuter> outer;
- readonly IUniTaskAsyncEnumerable<TInner> inner;
- readonly Func<TOuter, UniTask<TKey>> outerKeySelector;
- readonly Func<TInner, UniTask<TKey>> innerKeySelector;
- readonly Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector;
- readonly IEqualityComparer<TKey> comparer;
- CancellationToken cancellationToken;
- ILookup<TKey, TInner> lookup;
- IUniTaskAsyncEnumerator<TOuter> enumerator;
- TOuter outerValue;
- UniTask<bool>.Awaiter awaiter;
- UniTask<TKey>.Awaiter outerKeyAwaiter;
- UniTask<TResult>.Awaiter resultAwaiter;
- public _GroupJoinAwait(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- this.outer = outer;
- this.inner = inner;
- this.outerKeySelector = outerKeySelector;
- this.innerKeySelector = innerKeySelector;
- this.resultSelector = resultSelector;
- this.comparer = comparer;
- this.cancellationToken = cancellationToken;
- TaskTracker.TrackActiveTask(this, 3);
- }
- public TResult Current { get; private set; }
- public UniTask<bool> MoveNextAsync()
- {
- cancellationToken.ThrowIfCancellationRequested();
- completionSource.Reset();
- if (lookup == null)
- {
- CreateLookup().Forget();
- }
- else
- {
- SourceMoveNext();
- }
- return new UniTask<bool>(this, completionSource.Version);
- }
- async UniTaskVoid CreateLookup()
- {
- try
- {
- lookup = await inner.ToLookupAwaitAsync(innerKeySelector, comparer, cancellationToken);
- enumerator = outer.GetAsyncEnumerator(cancellationToken);
- }
- catch (Exception ex)
- {
- completionSource.TrySetException(ex);
- return;
- }
- SourceMoveNext();
- }
- void SourceMoveNext()
- {
- try
- {
- awaiter = enumerator.MoveNextAsync().GetAwaiter();
- if (awaiter.IsCompleted)
- {
- MoveNextCore(this);
- }
- else
- {
- awaiter.SourceOnCompleted(MoveNextCoreDelegate, this);
- }
- }
- catch (Exception ex)
- {
- completionSource.TrySetException(ex);
- }
- }
- static void MoveNextCore(object state)
- {
- var self = (_GroupJoinAwait)state;
- if (self.TryGetResult(self.awaiter, out var result))
- {
- if (result)
- {
- try
- {
- self.outerValue = self.enumerator.Current;
- self.outerKeyAwaiter = self.outerKeySelector(self.outerValue).GetAwaiter();
- if (self.outerKeyAwaiter.IsCompleted)
- {
- OuterKeySelectCore(self);
- }
- else
- {
- self.outerKeyAwaiter.SourceOnCompleted(OuterKeySelectCoreDelegate, self);
- }
- }
- catch (Exception ex)
- {
- self.completionSource.TrySetException(ex);
- }
- }
- else
- {
- self.completionSource.TrySetResult(false);
- }
- }
- }
- static void OuterKeySelectCore(object state)
- {
- var self = (_GroupJoinAwait)state;
- if (self.TryGetResult(self.outerKeyAwaiter, out var result))
- {
- try
- {
- var values = self.lookup[result];
- self.resultAwaiter = self.resultSelector(self.outerValue, values).GetAwaiter();
- if (self.resultAwaiter.IsCompleted)
- {
- ResultSelectCore(self);
- }
- else
- {
- self.resultAwaiter.SourceOnCompleted(ResultSelectCoreDelegate, self);
- }
- }
- catch (Exception ex)
- {
- self.completionSource.TrySetException(ex);
- }
- }
- }
- static void ResultSelectCore(object state)
- {
- var self = (_GroupJoinAwait)state;
- if (self.TryGetResult(self.resultAwaiter, out var result))
- {
- self.Current = result;
- self.completionSource.TrySetResult(true);
- }
- }
- public UniTask DisposeAsync()
- {
- TaskTracker.RemoveTracking(this);
- if (enumerator != null)
- {
- return enumerator.DisposeAsync();
- }
- return default;
- }
- }
- }
- internal sealed class GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult> : IUniTaskAsyncEnumerable<TResult>
- {
- readonly IUniTaskAsyncEnumerable<TOuter> outer;
- readonly IUniTaskAsyncEnumerable<TInner> inner;
- readonly Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector;
- readonly Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector;
- readonly Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector;
- readonly IEqualityComparer<TKey> comparer;
- public GroupJoinAwaitWithCancellation(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
- {
- this.outer = outer;
- this.inner = inner;
- this.outerKeySelector = outerKeySelector;
- this.innerKeySelector = innerKeySelector;
- this.resultSelector = resultSelector;
- this.comparer = comparer;
- }
- public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
- {
- return new _GroupJoinAwaitWithCancellation(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
- }
- sealed class _GroupJoinAwaitWithCancellation : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
- {
- static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
- readonly static Action<object> ResultSelectCoreDelegate = ResultSelectCore;
- readonly static Action<object> OuterKeySelectCoreDelegate = OuterKeySelectCore;
- readonly IUniTaskAsyncEnumerable<TOuter> outer;
- readonly IUniTaskAsyncEnumerable<TInner> inner;
- readonly Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector;
- readonly Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector;
- readonly Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector;
- readonly IEqualityComparer<TKey> comparer;
- CancellationToken cancellationToken;
- ILookup<TKey, TInner> lookup;
- IUniTaskAsyncEnumerator<TOuter> enumerator;
- TOuter outerValue;
- UniTask<bool>.Awaiter awaiter;
- UniTask<TKey>.Awaiter outerKeyAwaiter;
- UniTask<TResult>.Awaiter resultAwaiter;
- public _GroupJoinAwaitWithCancellation(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- this.outer = outer;
- this.inner = inner;
- this.outerKeySelector = outerKeySelector;
- this.innerKeySelector = innerKeySelector;
- this.resultSelector = resultSelector;
- this.comparer = comparer;
- this.cancellationToken = cancellationToken;
- TaskTracker.TrackActiveTask(this, 3);
- }
- public TResult Current { get; private set; }
- public UniTask<bool> MoveNextAsync()
- {
- cancellationToken.ThrowIfCancellationRequested();
- completionSource.Reset();
- if (lookup == null)
- {
- CreateLookup().Forget();
- }
- else
- {
- SourceMoveNext();
- }
- return new UniTask<bool>(this, completionSource.Version);
- }
- async UniTaskVoid CreateLookup()
- {
- try
- {
- lookup = await inner.ToLookupAwaitWithCancellationAsync(innerKeySelector, comparer, cancellationToken);
- enumerator = outer.GetAsyncEnumerator(cancellationToken);
- }
- catch (Exception ex)
- {
- completionSource.TrySetException(ex);
- return;
- }
- SourceMoveNext();
- }
- void SourceMoveNext()
- {
- try
- {
- awaiter = enumerator.MoveNextAsync().GetAwaiter();
- if (awaiter.IsCompleted)
- {
- MoveNextCore(this);
- }
- else
- {
- awaiter.SourceOnCompleted(MoveNextCoreDelegate, this);
- }
- }
- catch (Exception ex)
- {
- completionSource.TrySetException(ex);
- }
- }
- static void MoveNextCore(object state)
- {
- var self = (_GroupJoinAwaitWithCancellation)state;
- if (self.TryGetResult(self.awaiter, out var result))
- {
- if (result)
- {
- try
- {
- self.outerValue = self.enumerator.Current;
- self.outerKeyAwaiter = self.outerKeySelector(self.outerValue, self.cancellationToken).GetAwaiter();
- if (self.outerKeyAwaiter.IsCompleted)
- {
- OuterKeySelectCore(self);
- }
- else
- {
- self.outerKeyAwaiter.SourceOnCompleted(OuterKeySelectCoreDelegate, self);
- }
- }
- catch (Exception ex)
- {
- self.completionSource.TrySetException(ex);
- }
- }
- else
- {
- self.completionSource.TrySetResult(false);
- }
- }
- }
- static void OuterKeySelectCore(object state)
- {
- var self = (_GroupJoinAwaitWithCancellation)state;
- if (self.TryGetResult(self.outerKeyAwaiter, out var result))
- {
- try
- {
- var values = self.lookup[result];
- self.resultAwaiter = self.resultSelector(self.outerValue, values, self.cancellationToken).GetAwaiter();
- if (self.resultAwaiter.IsCompleted)
- {
- ResultSelectCore(self);
- }
- else
- {
- self.resultAwaiter.SourceOnCompleted(ResultSelectCoreDelegate, self);
- }
- }
- catch (Exception ex)
- {
- self.completionSource.TrySetException(ex);
- }
- }
- }
- static void ResultSelectCore(object state)
- {
- var self = (_GroupJoinAwaitWithCancellation)state;
- if (self.TryGetResult(self.resultAwaiter, out var result))
- {
- self.Current = result;
- self.completionSource.TrySetResult(true);
- }
- }
- public UniTask DisposeAsync()
- {
- TaskTracker.RemoveTracking(this);
- if (enumerator != null)
- {
- return enumerator.DisposeAsync();
- }
- return default;
- }
- }
- }
- }
|