@@ -9,22 +9,22 @@ let addTest1 = (t, x) => tests->Js.Array2.push((. ()) => t(. x))->ignore
9
9
//
10
10
// Basic tests
11
11
12
- let foo = @async (. x , y ) => x + y
12
+ let foo = @res. async (. x , y ) => x + y
13
13
14
14
let bar =
15
- @async
15
+ @res. async
16
16
(. ff ) => {
17
- let a = @await ff (. 3 , 4 )
18
- let b = @await foo (. 5 , 6 )
17
+ let a = @res. await ff (. 3 , 4 )
18
+ let b = @res. await foo (. 5 , 6 )
19
19
a + b
20
20
}
21
21
22
- let baz = @async (. ()) => @await bar (. foo )
22
+ let baz = @res. async (. ()) => @res. await bar (. foo )
23
23
24
24
let testBaz : testable =
25
- @async
25
+ @res. async
26
26
(. ()) => {
27
- let n = @await baz (.)
27
+ let n = @res. await baz (.)
28
28
Js .log2 ("baz returned" , n )
29
29
}
30
30
@@ -36,16 +36,16 @@ testBaz->addTest
36
36
37
37
exception E (int )
38
38
39
- let e1 : testable = @async (. ()) => raise (E (1000 ))
40
- let e2 : testable = @async (. ()) => Js .Exn .raiseError ("Some JS error" )
41
- let e3 : testable = @async (. ()) => @await e1 (.)
42
- let e4 : testable = @async (. ()) => @await e2 (.)
39
+ let e1 : testable = @res. async (. ()) => raise (E (1000 ))
40
+ let e2 : testable = @res. async (. ()) => Js .Exn .raiseError ("Some JS error" )
41
+ let e3 : testable = @res. async (. ()) => @res. await e1 (.)
42
+ let e4 : testable = @res. async (. ()) => @res. await e2 (.)
43
43
let e5 : testable = %raw (` function () { return Promise .reject (new Error (' fail' )) }` )
44
44
45
45
let testTryCatch =
46
- @async
46
+ @res. async
47
47
(. fn ) =>
48
- try {@await fn (.)} catch {
48
+ try {@res. await fn (.)} catch {
49
49
| E (n ) => Js .log2 ("testTryCatch: E" , n )
50
50
| JsError (_ ) => Js .log ("testTryCatch: JsError" )
51
51
}
@@ -60,10 +60,10 @@ testTryCatch->addTest1(e5)
60
60
//
61
61
// Check for nested promise
62
62
63
- let singlePromise = @async (. x ) => x + 1
63
+ let singlePromise = @res. async (. x ) => x + 1
64
64
65
65
let nestedPromise =
66
- @async
66
+ @res. async
67
67
(. x ) => {
68
68
let resolve = x => [Js .Promise .resolve (x )]
69
69
let _result = singlePromise (. x + 1 )-> resolve
@@ -84,10 +84,10 @@ module Fetch = {
84
84
let explainError : unknown => string = %raw (` (e )=> e .toString ()` )
85
85
86
86
let testFetch =
87
- @async
87
+ @res. async
88
88
(. url ) => {
89
89
open Fetch
90
- switch {@await fetch (url )} {
90
+ switch {@res. await fetch (url )} {
91
91
| response =>
92
92
let status = response -> status
93
93
Js .log2 ("Fetch returned status:" , status )
@@ -102,13 +102,13 @@ testFetch->addTest1("https://www.google.comsdkjdkghdsg")
102
102
//
103
103
// Callbacks
104
104
let withCallback =
105
- @async
105
+ @res. async
106
106
(. ()) => {
107
- @async (. x ) => @await (x -> Js .Promise .resolve ) + 1
107
+ @res. async (. x ) => @res. await (x -> Js .Promise .resolve ) + 1
108
108
}
109
109
110
110
let testWithCallback =
111
- @async (. ()) => Js .log2 ("callback returned" , @await (@await withCallback (.))(. 3 ))
111
+ @res. async (. ()) => Js .log2 ("callback returned" , @res. await (@res. await withCallback (.))(. 3 ))
112
112
113
113
testWithCallback -> addTest
114
114
@@ -117,17 +117,17 @@ testWithCallback->addTest
117
117
// Async list
118
118
module AsyncList = {
119
119
let map =
120
- @async
120
+ @res. async
121
121
(. l , f ) => {
122
122
let rec loop =
123
- @async
123
+ @res. async
124
124
(. l , acc ) =>
125
125
switch l {
126
126
| list {} => acc
127
- | list {p , ... rest } => @await loop (. rest , list {@await p , ... acc })
127
+ | list {p , ... rest } => @res. await loop (. rest , list {@res. await p , ... acc })
128
128
}
129
129
130
- @await
130
+ @res. await
131
131
loop (. l -> Belt .List .mapReverse (x => f (. x )), list {})
132
132
}
133
133
}
@@ -136,9 +136,9 @@ let fetchAndCount = {
136
136
let counter = ref (0 )
137
137
138
138
let ff =
139
- @async
139
+ @res. async
140
140
(. url ) => {
141
- let response = @await Fetch .fetch (url )
141
+ let response = @res. await Fetch .fetch (url )
142
142
counter := counter .contents + 1
143
143
(counter .contents , response -> Fetch .status )
144
144
}
@@ -147,10 +147,10 @@ let fetchAndCount = {
147
147
}
148
148
149
149
let testFetchMany =
150
- @async
150
+ @res. async
151
151
(. ()) => {
152
152
let fetchedItems =
153
- @await
153
+ @res. await
154
154
AsyncList .map (.
155
155
list {
156
156
"https://www.google.com" ,
@@ -170,9 +170,9 @@ testFetchMany->addTest
170
170
// Fetch with Result type
171
171
module FetchResult = {
172
172
let fetch =
173
- @async
173
+ @res. async
174
174
(. url ) => {
175
- switch {@await Fetch .fetch (url )} {
175
+ switch {@res. await Fetch .fetch (url )} {
176
176
| response => Ok (response )
177
177
| exception JsError (e ) => Error (e )
178
178
}
@@ -182,16 +182,16 @@ module FetchResult = {
182
182
let nextFetch = (. _response ) => Some ("https://github.com/" )
183
183
184
184
let testFetchWithResult =
185
- @async
185
+ @res. async
186
186
(. ()) => {
187
- switch @await
187
+ switch @res. await
188
188
FetchResult .fetch (. "https://www.google.com" ) {
189
189
| Ok (response1 ) =>
190
190
Js .log2 ("FetchResult response1" , response1 -> Fetch .status )
191
191
switch nextFetch (. response1 ) {
192
192
| None => ()
193
193
| Some (url ) =>
194
- switch @await
194
+ switch @res. await
195
195
FetchResult .fetch (. url ) {
196
196
| Ok (response2 ) => Js .log2 ("FetchResult response2" , response2 -> Fetch .status )
197
197
| Error (_ ) => ()
@@ -216,13 +216,13 @@ testFetchWithResult->addTest
216
216
// Run tests
217
217
218
218
let rec runAllTests =
219
- @async
219
+ @res. async
220
220
(. n ) => {
221
221
if n >= 0 && n < Array .length (tests ) {
222
- @await
222
+ @res. await
223
223
(@doesNotRaise tests [n ])(.)
224
224
225
- @await
225
+ @res. await
226
226
runAllTests (. n + 1 )
227
227
}
228
228
}
@@ -233,23 +233,23 @@ runAllTests(. 0)->ignore
233
233
//
234
234
// Curried functions
235
235
236
- let bb = @async x => @await x
236
+ let bb = @res. async x => @res. await x
237
237
238
- let cc = @async (x , ~y = x , z ) => @ await x + @ await y + @ await z
238
+ let cc = @res. async (x , ~y = x , z ) => (@ res. await x ) + (@ res. await y ) + (@ res. await z )
239
239
240
- let dd = @async x => {y => @ await x + @ await y }
240
+ let dd = @res. async x => {y => (@ res. await x ) + (@ res. await y ) }
241
241
242
- let ee = @async (. x ) => {y => @ await x + @ await y }
242
+ let ee = @res. async (. x ) => {y => (@ res. await x ) + (@ res. await y ) }
243
243
244
244
//
245
245
//
246
246
// Errors
247
247
248
248
// let aa =
249
- // @async
249
+ // @res. async
250
250
// (. x) => {
251
- // let cb = (. _) => @await x // Error: Await on expression not in an async context
251
+ // let cb = (. _) => @res. await x // Error: Await on expression not in an async context
252
252
// cb
253
253
// }
254
254
255
- // let _ = @async (_, . x) => @await x // Error: Await on expression not in an async context
255
+ // let _ = @res. async (_, . x) => @res. await x // Error: Await on expression not in an async context
0 commit comments