You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `All` function combines multiple async operations to run in parallel. It converts a collection of promises or a variable length parameter list of promises into a single promise that yields a collection.
574
+
The `All` function combines multiple async operations that are currently running. It converts a collection of promises or a variable length parameter list of promises into a single promise, and if those promises are non-void, it yields a list containing the results of those promises in the same order.
570
575
571
-
Say that each promise yields a value of type T, the resulting promise then yields a collection with values of type T.
576
+
Say that each promise yields a value of type `string`, the resulting promise then yields an `IList<string>`.
572
577
573
578
Here is an example that extracts links from multiple pages and merges the results:
Progress from an All promise will be normalized from all of the input promises.
592
597
593
-
### Merge Parallel
598
+
### Merge
594
599
595
600
The `Merge` function behaves just like the `All` function, except that it can be used to combine multiple types, and instead of yielding an `IList<T>`, it yields a `ValueTuple<>` that contains the types of the promises provided to the function.
The `AllSettled` and `MergeSettled` functions behave very similar to `All` and `Merge`, except they yield a collection/tuple of `ResultContainer`s instead of the raw type. This is because they capture the state of each promise. The returned promise waits until all promises are complete, whether they are resolved, rejected, or canceled (in contrast, `All` and `Merge` immediately reject or cancel the returned promise when any promise is rejected or canceled).
614
+
615
+
```cs
616
+
Promise.MergeSettled(Download("http://www.google.com"), DownloadImage("http://www.example.com/image.jpg")) // Download HTML and image.
Console.WriteLine(result1.Value); // Print the HTML.
624
+
}
625
+
elseif (result1.State==Promise.State.Rejected)
626
+
{
627
+
Console.WriteLine(result1.Reason); // Print the reject reason.
628
+
}
629
+
630
+
if (result2.State==Promise.State.Resolved)
631
+
{
632
+
image.SetTexture(result2.Value); // Assign the texture to an image object.
633
+
}
634
+
elseif (result2.State==Promise.State.Rejected)
635
+
{
636
+
Console.WriteLine(result2.Reason); // Print the reject reason.
637
+
}
638
+
})
639
+
```
640
+
641
+
### Race
607
642
608
643
The `Race` function is similar to the `All` function, but it is the first async operation that settles that wins the race and the promise adopts its state.
Progress from a Race promise will be the maximum of those reported by all the input promises.
617
652
618
-
### First Parallel
653
+
### First
619
654
620
655
The `First` function is almost idential to `Race` except that if a promise is rejected or canceled, the First promise will remain pending until one of the input promises is resolved or they are all rejected/canceled.
621
656
@@ -1049,7 +1084,7 @@ Normally when you await a promise in an `async Promise` function, it will throw
Copy file name to clipboardexpand all lines: ProtoPromiseUnityHelpers/ProtoPromiseUnityHelpers.csproj
+1-1
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
<!--We target .Net Framework 3.5 to support old Unity versions, and we also target .Net Standard 2.1 to support new Unity versions, even after it drops old Framework support.-->
0 commit comments