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
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/promise.mdx
+2-68Lines changed: 2 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ order: 21
14
14
15
15
**Since 10.1**
16
16
17
-
In ReScript, every JS promise is represented with the globally available `promise<'a>` type. For ReScript versions < 10.1, use its original alias `Js.Promise.t<'a>` instead.
17
+
In ReScript, every JS promise is represented with the globally available `promise<'a>` type.
18
18
19
19
Here's a usage example in a function signature:
20
20
@@ -112,70 +112,4 @@ async function logAsyncMessage(param) {
112
112
export { logAsyncMessage };
113
113
```
114
114
115
-
</CodeTab>
116
-
117
-
## Js.Promise module (legacy - do not use)
118
-
119
-
> **Note:** The `Js.Promise` bindings are following the outdated data-last convention from a few years ago. We kept those APIs for backwards compatibility. Either use [`Promise`](/docs/manual/api/stdlib/promise) or a third-party promise binding instead.
120
-
121
-
ReScript has built-in support for [JavaScript promises](/docs/manual/api/stdlib/promise). The 3 functions you generally need are:
Additionally, here's the type signature for creating a promise on the ReScript side:
128
-
129
-
```res
130
-
Js.Promise.make: (
131
-
(
132
-
~resolve: (. 'a) => unit,
133
-
~reject: (. exn) => unit
134
-
) => unit
135
-
) => Js.Promise.t<'a>
136
-
```
137
-
138
-
This type signature means that `make` takes a callback that takes 2 named arguments, `resolve` and `reject`. Both arguments are themselves [uncurried callbacks](./function.mdx#uncurried-function) (with a dot). `make` returns the created promise.
139
-
140
-
### Usage
141
-
142
-
Using the [pipe operator](./pipe.mdx):
143
-
144
-
<CodeTablabels={["ReScript", "JS Output"]}>
145
-
146
-
```res example
147
-
let myPromise = Js.Promise.make((~resolve, ~reject) => resolve(. 2))
148
-
149
-
myPromise->Js.Promise.then_(value => {
150
-
Console.log(value)
151
-
Js.Promise.resolve(value + 2)
152
-
}, _)->Js.Promise.then_(value => {
153
-
Console.log(value)
154
-
Js.Promise.resolve(value + 3)
155
-
}, _)->Js.Promise.catch(err => {
156
-
Console.log2("Failure!!", err)
157
-
Js.Promise.resolve(-2)
158
-
}, _)
159
-
```
160
-
161
-
```js
162
-
var myPromise =newPromise(function (resolve, reject) {
0 commit comments