Skip to content

Commit 485e537

Browse files
committed
Switch over await's to surface syntax.
1 parent 09875bc commit 485e537

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

example-async/src/AA.res

+25-25
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ let foo = async (. x, y) => x + y
1414
let bar =
1515
async
1616
(. ff) => {
17-
let a = @res.await ff(. 3, 4)
18-
let b = @res.await foo(. 5, 6)
17+
let a = await ff(. 3, 4)
18+
let b = await foo(. 5, 6)
1919
a + b
2020
}
2121

22-
let baz = async (. ()) => @res.await bar(. foo)
22+
let baz = async (. ()) => await bar(. foo)
2323

2424
let testBaz: testable =
2525
async
2626
(. ()) => {
27-
let n = @res.await baz(.)
27+
let n = await baz(.)
2828
Js.log2("baz returned", n)
2929
}
3030

@@ -38,14 +38,14 @@ exception E(int)
3838

3939
let e1: testable = async (. ()) => raise(E(1000))
4040
let e2: testable = async (. ()) => Js.Exn.raiseError("Some JS error")
41-
let e3: testable = async (. ()) => @res.await e1(.)
42-
let e4: testable = async (. ()) => @res.await e2(.)
41+
let e3: testable = async (. ()) => await e1(.)
42+
let e4: testable = async (. ()) => await e2(.)
4343
let e5: testable = %raw(`function() { return Promise.reject(new Error('fail')) }`)
4444

4545
let testTryCatch =
4646
async
4747
(. fn) =>
48-
try {@res.await fn(.)} catch {
48+
try {await fn(.)} catch {
4949
| E(n) => Js.log2("testTryCatch: E", n)
5050
| JsError(_) => Js.log("testTryCatch: JsError")
5151
}
@@ -87,7 +87,7 @@ let testFetch =
8787
async
8888
(. url) => {
8989
open Fetch
90-
switch {@res.await fetch(url)} {
90+
switch {await fetch(url)} {
9191
| response =>
9292
let status = response->status
9393
Js.log2("Fetch returned status:", status)
@@ -104,11 +104,11 @@ testFetch->addTest1("https://www.google.comsdkjdkghdsg")
104104
let withCallback =
105105
async
106106
(. ()) => {
107-
async (. x) => @res.await (x->Js.Promise.resolve) + 1
107+
async (. x) => await (x->Js.Promise.resolve) + 1
108108
}
109109

110110
let testWithCallback =
111-
async (. ()) => Js.log2("callback returned", @res.await (@res.await withCallback(.))(. 3))
111+
async (. ()) => Js.log2("callback returned", await (await withCallback(.))(. 3))
112112

113113
testWithCallback->addTest
114114

@@ -124,10 +124,10 @@ module AsyncList = {
124124
(. l, acc) =>
125125
switch l {
126126
| list{} => acc
127-
| list{p, ...rest} => @res.await loop(. rest, list{@res.await p, ...acc})
127+
| list{p, ...rest} => await loop(. rest, list{await p, ...acc})
128128
}
129129

130-
@res.await
130+
await
131131
loop(. l->Belt.List.mapReverse(x => f(. x)), list{})
132132
}
133133
}
@@ -138,7 +138,7 @@ let fetchAndCount = {
138138
let ff =
139139
async
140140
(. url) => {
141-
let response = @res.await Fetch.fetch(url)
141+
let response = await Fetch.fetch(url)
142142
counter := counter.contents + 1
143143
(counter.contents, response->Fetch.status)
144144
}
@@ -150,7 +150,7 @@ let testFetchMany =
150150
async
151151
(. ()) => {
152152
let fetchedItems =
153-
@res.await
153+
await
154154
AsyncList.map(.
155155
list{
156156
"https://www.google.com",
@@ -172,7 +172,7 @@ module FetchResult = {
172172
let fetch =
173173
async
174174
(. url) => {
175-
switch {@res.await Fetch.fetch(url)} {
175+
switch {await Fetch.fetch(url)} {
176176
| response => Ok(response)
177177
| exception JsError(e) => Error(e)
178178
}
@@ -184,14 +184,14 @@ let nextFetch = (. _response) => Some("https://github.com/")
184184
let testFetchWithResult =
185185
async
186186
(. ()) => {
187-
switch @res.await
187+
switch await
188188
FetchResult.fetch(. "https://www.google.com") {
189189
| Ok(response1) =>
190190
Js.log2("FetchResult response1", response1->Fetch.status)
191191
switch nextFetch(. response1) {
192192
| None => ()
193193
| Some(url) =>
194-
switch @res.await
194+
switch await
195195
FetchResult.fetch(. url) {
196196
| Ok(response2) => Js.log2("FetchResult response2", response2->Fetch.status)
197197
| Error(_) => ()
@@ -219,10 +219,10 @@ let rec runAllTests =
219219
async
220220
(. n) => {
221221
if n >= 0 && n < Array.length(tests) {
222-
@res.await
222+
await
223223
(@doesNotRaise tests[n])(.)
224224

225-
@res.await
225+
await
226226
runAllTests(. n + 1)
227227
}
228228
}
@@ -233,13 +233,13 @@ runAllTests(. 0)->ignore
233233
//
234234
// Curried functions
235235

236-
let bb = async x => @res.await x
236+
let bb = async x => await x
237237

238-
let cc = async (x, ~y=x, z) => (@res.await x) + (@res.await y) + (@res.await z)
238+
let cc = async (x, ~y=x, z) => (await x) + (await y) + (await z)
239239

240-
let dd = async x => {y => (@res.await x) + (@res.await y)}
240+
let dd = async x => {y => (await x) + (await y)}
241241

242-
let ee = async (. x) => {y => (@res.await x) + (@res.await y)}
242+
let ee = async (. x) => {y => (await x) + (await y)}
243243

244244
//
245245
//
@@ -248,8 +248,8 @@ let ee = async (. x) => {y => (@res.await x) + (@res.await y)}
248248
// let aa =
249249
// async
250250
// (. x) => {
251-
// let cb = (. _) => @res.await x // Error: Await on expression not in an async context
251+
// let cb = (. _) => await x // Error: Await on expression not in an async context
252252
// cb
253253
// }
254254

255-
// let _ = async (_, . x) => @res.await x // Error: Await on expression not in an async context
255+
// let _ = async (_, . x) => await x // Error: Await on expression not in an async context

0 commit comments

Comments
 (0)