Skip to content

Commit 7373ade

Browse files
fitsyutemrich
authored and
temrich
committed
add statement about the number of promises all can handle (#120)
* add statement about the number of promises `all` can handle This is extra useful solution for issue #109. * elaborate notes for limitation of `all` and `any` * add limitation information for `any` operator similar to `all` limitation, this one also needs to be explained for users * fix misplaced words
1 parent 43cbee9 commit 7373ade

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

g3doc/index.md

+24
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,19 @@ method on `NSArray`, which often comes handy, along with other similar
10721072
[functional operators](https://github.com/google/functional-objc) that
10731073
Objective-C lacks.
10741074
1075+
1076+
Note: In Swift, the number of promises of heterogeneous types that `all` can handle is 4. If you need more than 4,
1077+
you can break the promises down into separate `all` and then group them together.
1078+
For example:
1079+
1080+
Swift:
1081+
```swift
1082+
all(all(p1, p2, p3), all(p4, p5, p6)).then { results in
1083+
let ((a1, a2, a3), (a4, a5, a6)) = results
1084+
print(a1, a2, a3, a4, a5, a6)
1085+
}
1086+
```
1087+
10751088
Also, see how `all` helps to avoid [nested promises](#nested-promises).
10761089

10771090
### Always
@@ -1188,6 +1201,17 @@ methods on `NSArray`, which often comes handy, along with other similar
11881201
[functional operators](https://github.com/google/functional-objc) that
11891202
Objective-C lacks.
11901203
1204+
Note: In Swift, the number of promises of heterogeneous types that `any` can handle is 3. If you need more than 3,
1205+
you can break the promises down into separate `any` and then group them together. It is similar to what you can do with [`all`](#all).
1206+
1207+
For example:
1208+
1209+
```Swift
1210+
any( any(p1, p2), any(p3, p4)).then { results in
1211+
dump(results) // a tuple containing two MayBe's. each contains their respective MayBe values
1212+
}
1213+
```
1214+
11911215
### Await
11921216

11931217
Using `await` you can synchronously wait for a promise to get resolved

0 commit comments

Comments
 (0)