#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Threading; using UniRx.Async.Internal; namespace UniRx.Async { public partial struct UniTask { public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> WhenAny(UniTask task1, UniTask task2) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2))>(new WhenAnyPromise(task1, task2), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2))> core; public WhenAnyPromise(UniTask task1, UniTask task2) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> WhenAny(UniTask task1, UniTask task2, UniTask task3) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))>(new WhenAnyPromise(task1, task2, task3), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))>(new WhenAnyPromise(task1, task2, task3, task4), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))>(new WhenAnyPromise(task1, task2, task3, task4, task5), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task9.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT9(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT9(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T9 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task9.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT9(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT9(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task10.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT10(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT10(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T9 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T10 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task9.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT9(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT9(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task10.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT10(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT10(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task11.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT11(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT11(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T9 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T10 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T11 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task9.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT9(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT9(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task10.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT10(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT10(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task11.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT11(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT11(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task12.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT12(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT12(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T9 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T10 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T11 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T12 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task9.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT9(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT9(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task10.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT10(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT10(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task11.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT11(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT11(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task12.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT12(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT12(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task13.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT13(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT13(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T9 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T10 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T11 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T12 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT13(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T13 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task9.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT9(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT9(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task10.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT10(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT10(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task11.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT11(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT11(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task12.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT12(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT12(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task13.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT13(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT13(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task14.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT14(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT14(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T9 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T10 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T11 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T12 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT13(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T13 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT14(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T14 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((13, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } public static UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { return new UniTask<(int winArgumentIndex, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))>(new WhenAnyPromise(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14, task15), 0); } sealed class WhenAnyPromise : IUniTaskSource<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> { int completedCount; UniTaskCompletionSourceCore<(int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15))> core; public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { TaskTracker2.TrackActiveTask(this, 3); this.completedCount = 0; { var awaiter = task1.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT1(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT1(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task2.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT2(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT2(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task3.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT3(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT3(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task4.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT4(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT4(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task5.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT5(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT5(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task6.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT6(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT6(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task7.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT7(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT7(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task8.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT8(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT8(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task9.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT9(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT9(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task10.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT10(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT10(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task11.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT11(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT11(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task12.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT12(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT12(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task13.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT13(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT13(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task14.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT14(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT14(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } { var awaiter = task15.GetAwaiter(); if (awaiter.IsCompleted) { TryInvokeContinuationT15(this, awaiter); } else { awaiter.SourceOnCompleted(state => { using (var t = (StateTuple, UniTask.Awaiter>)state) { TryInvokeContinuationT15(t.Item1, t.Item2); } }, StateTuple.Create(this, awaiter)); } } } static void TryInvokeContinuationT1(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T1 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((0, (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT2(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T2 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((1, (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT3(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T3 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((2, (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT4(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T4 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((3, (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT5(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T5 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((4, (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT6(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T6 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((5, (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT7(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T7 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((6, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT8(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T8 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((7, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT9(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T9 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((8, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT10(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T10 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((9, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT11(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T11 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((10, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT12(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T12 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((11, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default), (false, default))); } } static void TryInvokeContinuationT13(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T13 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((12, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default), (false, default))); } } static void TryInvokeContinuationT14(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T14 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((13, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result), (false, default))); } } static void TryInvokeContinuationT15(WhenAnyPromise self, in UniTask.Awaiter awaiter) { T15 result; try { result = awaiter.GetResult(); } catch (Exception ex) { self.core.TrySetException(ex); return; } if (Interlocked.Increment(ref self.completedCount) == 1) { self.core.TrySetResult((14, (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (false, default), (true, result))); } } public (int, (bool hasResult, T1 result1), (bool hasResult, T2 result2), (bool hasResult, T3 result3), (bool hasResult, T4 result4), (bool hasResult, T5 result5), (bool hasResult, T6 result6), (bool hasResult, T7 result7), (bool hasResult, T8 result8), (bool hasResult, T9 result9), (bool hasResult, T10 result10), (bool hasResult, T11 result11), (bool hasResult, T12 result12), (bool hasResult, T13 result13), (bool hasResult, T14 result14), (bool hasResult, T15 result15)) GetResult(short token) { TaskTracker2.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } public UniTaskStatus GetStatus(short token) { return core.GetStatus(token); } public void OnCompleted(Action continuation, object state, short token) { core.OnCompleted(continuation, state, token); } public UniTaskStatus UnsafeGetStatus() { return core.UnsafeGetStatus(); } void IUniTaskSource.GetResult(short token) { GetResult(token); } ~WhenAnyPromise() { core.Reset(); } } } }