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