Skip to content

Commit

Permalink
add statement about the number of promises all can handle (google#120)
Browse files Browse the repository at this point in the history
* add statement about the number of promises `all` can handle

This is extra useful solution for issue google#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
  • Loading branch information
fitsyu authored and temrich committed Jul 29, 2019
1 parent 43cbee9 commit 7373ade
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions g3doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,19 @@ method on `NSArray`, which often comes handy, along with other similar
[functional operators](https://github.com/google/functional-objc) that
Objective-C lacks.
Note: In Swift, the number of promises of heterogeneous types that `all` can handle is 4. If you need more than 4,
you can break the promises down into separate `all` and then group them together.
For example:
Swift:
```swift
all(all(p1, p2, p3), all(p4, p5, p6)).then { results in
let ((a1, a2, a3), (a4, a5, a6)) = results
print(a1, a2, a3, a4, a5, a6)
}
```

Also, see how `all` helps to avoid [nested promises](#nested-promises).

### Always
Expand Down Expand Up @@ -1188,6 +1201,17 @@ methods on `NSArray`, which often comes handy, along with other similar
[functional operators](https://github.com/google/functional-objc) that
Objective-C lacks.
Note: In Swift, the number of promises of heterogeneous types that `any` can handle is 3. If you need more than 3,
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).
For example:
```Swift
any( any(p1, p2), any(p3, p4)).then { results in
dump(results) // a tuple containing two MayBe's. each contains their respective MayBe values
}
```

### Await

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

0 comments on commit 7373ade

Please sign in to comment.