Skip to content

Commit

Permalink
Added and fixed MergeSettled tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Sep 10, 2023
1 parent 3be71a8 commit 17958f1
Show file tree
Hide file tree
Showing 5 changed files with 694 additions and 19 deletions.
32 changes: 14 additions & 18 deletions Package/Core/Promises/PromiseStaticMergeSettled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ internal static Internal.GetResultContainerDelegate<ValueTuple<ResultContainer,
/// <summary>
/// Returns a <see cref="Promise{T}"/> that will resolve with the result container of each promise when they have all completed.
/// </summary>
public static Promise<ValueTuple<ResultContainer, ResultContainer>> MergeSettled<T1>(Promise promise1, Promise promise2)
public static Promise<ValueTuple<ResultContainer, ResultContainer>> MergeSettled(Promise promise1, Promise promise2)
{
var passThroughs = new Internal.ValueLinkedStack<Internal.PromiseRefBase.PromisePassThrough>();
int pendingCount = 0;
Expand Down Expand Up @@ -590,7 +590,7 @@ internal static Internal.GetResultContainerDelegate<ValueTuple<ResultContainer,
/// <summary>
/// Returns a <see cref="Promise{T}"/> that will resolve with the result container of each promise when they have all completed.
/// </summary>
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer>> Merge(
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer>> MergeSettled(
Promise promise1, Promise promise2, Promise promise3)
{
var passThroughs = new Internal.ValueLinkedStack<Internal.PromiseRefBase.PromisePassThrough>();
Expand Down Expand Up @@ -906,7 +906,7 @@ internal static Internal.GetResultContainerDelegate<ValueTuple<ResultContainer,
/// <summary>
/// Returns a <see cref="Promise{T}"/> that will resolve with the result container of each promise when they have all completed.
/// </summary>
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer>> Merge(
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer>> MergeSettled(
Promise promise1, Promise promise2, Promise promise3, Promise promise4)
{
var passThroughs = new Internal.ValueLinkedStack<Internal.PromiseRefBase.PromisePassThrough>();
Expand Down Expand Up @@ -1332,7 +1332,7 @@ internal static Internal.GetResultContainerDelegate<ValueTuple<ResultContainer,
/// <summary>
/// Returns a <see cref="Promise{T}"/> that will resolve with the result container of each promise when they have all completed.
/// </summary>
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer>> Merge(
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer>> MergeSettled(
Promise promise1, Promise promise2, Promise promise3, Promise promise4, Promise promise5)
{
var passThroughs = new Internal.ValueLinkedStack<Internal.PromiseRefBase.PromisePassThrough>();
Expand Down Expand Up @@ -1877,7 +1877,7 @@ internal static Internal.GetResultContainerDelegate<ValueTuple<ResultContainer,
/// <summary>
/// Returns a <see cref="Promise{T}"/> that will resolve with the result container of each promise when they have all completed.
/// </summary>
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer>> Merge(
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer>> MergeSettled(
Promise promise1, Promise promise2, Promise promise3, Promise promise4, Promise promise5, Promise promise6)
{
var passThroughs = new Internal.ValueLinkedStack<Internal.PromiseRefBase.PromisePassThrough>();
Expand Down Expand Up @@ -2307,7 +2307,7 @@ private static partial class MergeResultFuncs
private static class Settled1<T1, T2, T3, T4, T5>
{
[MethodImpl(Internal.InlineOption)]
private static void GetMergeResult(Internal.PromiseRefBase handler, object rejectContainer, State state, int index, ref ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer> result)
private static void GetMergeResult(Internal.PromiseRefBase handler, object rejectContainer, State state, int index, ref ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer> result)
{
switch (index)
{
Expand All @@ -2329,27 +2329,24 @@ private static void GetMergeResult(Internal.PromiseRefBase handler, object rejec
case 5:
result.Item6 = new ResultContainer(rejectContainer, state);
break;
case 6:
result.Item7 = new ResultContainer(rejectContainer, state);
break;
}
}

#if NETCOREAPP || UNITY_2021_2_OR_NEWER
internal static unsafe Internal.GetResultContainerDelegate<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer>> Func
internal static unsafe Internal.GetResultContainerDelegate<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer>> Func
{
[MethodImpl(Internal.InlineOption)]
get { return new(&GetMergeResult); }
}
#else
internal static readonly Internal.GetResultContainerDelegate<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer>>
Func = (Internal.PromiseRefBase handler, object rejectContainer, State state, int index, ref ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer> result)
internal static readonly Internal.GetResultContainerDelegate<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer>>
Func = (Internal.PromiseRefBase handler, object rejectContainer, State state, int index, ref ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer> result)
=> GetMergeResult(handler, rejectContainer, state, index, ref result);
#endif
}

[MethodImpl(Internal.InlineOption)]
internal static Internal.GetResultContainerDelegate<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer>>
internal static Internal.GetResultContainerDelegate<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer>>
GetSettled1<T1, T2, T3, T4, T5>()
{
return Settled1<T1, T2, T3, T4, T5>.Func;
Expand All @@ -2359,7 +2356,7 @@ private static void GetMergeResult(Internal.PromiseRefBase handler, object rejec
/// <summary>
/// Returns a <see cref="Promise{T}"/> that will resolve with the result container of each promise when they have all completed.
/// </summary>
public static Promise<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer>> MergeSettled<T1, T2, T3, T4, T5>(
public static Promise<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer>> MergeSettled<T1, T2, T3, T4, T5>(
Promise<T1> promise1, Promise<T2> promise2, Promise<T3> promise3, Promise<T4> promise4, Promise<T5> promise5, Promise promise6)
{
var passThroughs = new Internal.ValueLinkedStack<Internal.PromiseRefBase.PromisePassThrough>();
Expand All @@ -2385,20 +2382,19 @@ private static void GetMergeResult(Internal.PromiseRefBase handler, object rejec
ValidateArgument(promise6, "promise6", 1);
Internal.PrepareForMerge(promise6, ref passThroughs, 5, ref pendingCount, ref completedProgress, ref maxDepth);

var value = new ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer>(
var value = new ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer>(
v0,
v1,
v2,
v3,
v4,
ResultContainer.Resolved,
ResultContainer.Resolved);
if (pendingCount == 0)
{
return Internal.CreateResolved(value, maxDepth);
}
var promise = Internal.PromiseRefBase.GetOrCreateMergeSettledPromise(passThroughs, value, pendingCount, completedProgress, maxDepth, MergeResultFuncs.GetSettled1<T1, T2, T3, T4, T5>());
return new Promise<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer, ResultContainer>>(
return new Promise<ValueTuple<Promise<T1>.ResultContainer, Promise<T2>.ResultContainer, Promise<T3>.ResultContainer, Promise<T4>.ResultContainer, Promise<T5>.ResultContainer, ResultContainer>>(
promise, promise.Id, maxDepth);
}

Expand Down Expand Up @@ -2561,7 +2557,7 @@ internal static Internal.GetResultContainerDelegate<ValueTuple<ResultContainer,
/// <summary>
/// Returns a <see cref="Promise{T}"/> that will resolve with the result container of each promise when they have all completed.
/// </summary>
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer>> Merge(
public static Promise<ValueTuple<ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer, ResultContainer>> MergeSettled(
Promise promise1, Promise promise2, Promise promise3, Promise promise4, Promise promise5, Promise promise6, Promise promise7)
{
var passThroughs = new Internal.ValueLinkedStack<Internal.PromiseRefBase.PromisePassThrough>();
Expand Down
1 change: 0 additions & 1 deletion Package/Tests/CoreTests/APIs/AllSettledTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,6 @@ public void AllSettledProgressIsReportedFromRejected_void(
ProgressHelper progressHelper = new ProgressHelper(progressType, synchronizationType);
Promise.AllSettled(deferred1.Promise, deferred2.Promise, deferred3.Promise)
.SubscribeProgressAndAssert(progressHelper, 0f / 3f)
.Catch(() => { })
.Forget();

progressHelper.ReportProgressAndAssertResult(deferred1, 0.5f, 0.5f / 3f);
Expand Down
11 changes: 11 additions & 0 deletions Package/Tests/CoreTests/APIs/AllSettledTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 17958f1

Please sign in to comment.