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
`catch(promise, errorCallback)` registers an exception handler in a promise chain.
56
-
The `errorCallback` receives an `exn` value that can later be refined into a JS error or ReScript
57
-
error. The `errorCallback` needs to return a promise with the same type as the consumed promise.
79
+
The `errorCallback` receives an `exn` value that can later be refined into a JS
80
+
error or ReScript error. The `errorCallback` needs to return a promise with the
81
+
same type as the consumed promise. See [`Promise.catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) on MDN.
82
+
83
+
## Examples
58
84
59
85
```rescript
60
86
open Promise
@@ -87,15 +113,17 @@ reject(SomeError("this is an error"))
87
113
->ignore // Ignore needed for side-effects
88
114
```
89
115
90
-
In case you want to return another promise in your `callback`, consider using \`then\` instead.
116
+
In case you want to return another promise in your `callback`, consider using
117
+
`then` instead.
91
118
*/
92
119
letcatch: (t<'a>, exn=>t<'a>) =>t<'a>
93
120
94
121
/**
95
-
`then(promise, callback)` returns a new promise based on the result of `promise`'s value.
96
-
The `callback` needs to explicitly return a new promise via `resolve`.
97
-
122
+
`then(promise, callback)` returns a new promise based on the result of `promise`'s
123
+
value. The `callback` needs to explicitly return a new promise via `resolve`.
98
124
It is **not allowed** to resolve a nested promise (like `resolve(resolve(1))`).
125
+
See [`Promise.then`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) on MDN.
[finally(promise, callback)] is used to execute a function that is called no matter if a promise
138
-
was resolved or rejected. It will return the same `promise` it originally received.
168
+
`finally(promise, callback)` is used to execute a function that is called no
169
+
matter if a promise was resolved or rejected. It will return the same `promise`
170
+
it originally received. See [`Promise.finally`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally) on MDN.
`race(arr)` combining `array` of promises. See [`Promise.race`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race) on MDN.
206
+
207
+
## Examples
208
+
209
+
```rescript
210
+
open Promise
211
+
let racer = (ms, name) => {
212
+
Promise.make((resolve, _) => {
213
+
Global.setTimeout(() => {
214
+
resolve(. name)
215
+
}, ms)->ignore
216
+
})
217
+
}
218
+
219
+
let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")]
220
+
221
+
race(promises)->then(winner => {
222
+
Console.log("The winner is " ++ winner)
223
+
resolve()
224
+
})
225
+
```
226
+
*/
171
227
@scope("Promise") @val
172
228
externalrace: array<t<'a>> =>t<'a> ="race"
173
229
174
230
/**
175
-
[all(promises)] runs all promises in parallel and returns a new promise resolving all gathered results in a unified array.
231
+
`all(promises)` runs all promises in parallel and returns a new promise resolving
232
+
all gathered results in a unified array. See [`Promise.all`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) on MDN.
176
233
177
234
```rescript
178
235
open Promise
@@ -194,44 +251,46 @@ all(promises)
194
251
externalall: array<t<'a>> =>t<array<'a>> ="all"
195
252
196
253
/**
197
-
[all2((p1, p2))]. Like `all()`, but with a fixed size tuple of 2
254
+
`all2((p1, p2))`. Like `all()`, but with a fixed size tuple of 2
0 commit comments