1
- // Boilerplate currently handwritten
2
- external await : Js .Promise .t <'a > => 'a = "?await"
3
-
4
1
type testable = (. unit ) => Js .Promise .t <unit >
5
2
6
3
let tests : array <testable > = []
@@ -17,17 +14,17 @@ let foo = @async (. x, y) => x + y
17
14
let bar =
18
15
@async
19
16
(. ff ) => {
20
- let a = await ( ff (. 3 , 4 ) )
21
- let b = await ( foo (. 5 , 6 ) )
17
+ let a = @ await ff (. 3 , 4 )
18
+ let b = @ await foo (. 5 , 6 )
22
19
a + b
23
20
}
24
21
25
- let baz = @async (. ()) => await ( bar (. foo ) )
22
+ let baz = @async (. ()) => @ await bar (. foo )
26
23
27
24
let testBaz : testable =
28
25
@async
29
26
(. ()) => {
30
- let n = await ( baz (.) )
27
+ let n = @ await baz (.)
31
28
Js .log2 ("baz returned" , n )
32
29
}
33
30
@@ -41,14 +38,15 @@ exception E(int)
41
38
42
39
let e1 : testable = @async (. ()) => raise (E (1000 ))
43
40
let e2 : testable = @async (. ()) => Js .Exn .raiseError ("Some JS error" )
44
- let e3 : testable = @async (. ()) => await ( e1 (.) )
45
- let e4 : testable = @async (. ()) => await ( e2 (.) )
41
+ let e3 : testable = @async (. ()) => @ await e1 (.)
42
+ let e4 : testable = @async (. ()) => @ await e2 (.)
46
43
let e5 : testable = %raw (` function () { return Promise .reject (new Error (' fail' )) }` )
47
44
48
45
let testTryCatch =
49
46
@async
50
47
(. fn ) =>
51
- try await (fn (.)) catch {
48
+ try @await
49
+ fn (.) catch {
52
50
| E (n ) => Js .log2 ("testTryCatch: E" , n )
53
51
| JsError (_ ) => Js .log ("testTryCatch: JsError" )
54
52
}
@@ -82,7 +80,8 @@ let explainError: unknown => string = %raw(`(e)=>e.toString()`)
82
80
let testFetch =
83
81
@async
84
82
(. url ) => {
85
- switch await (Fetch .fetch (url )) {
83
+ switch @await
84
+ Fetch .fetch (url ) {
86
85
| response =>
87
86
let status = response -> Fetch .Response .status
88
87
Js .log2 ("Fetch returned status:" , status )
@@ -101,8 +100,11 @@ let rec runAllTests =
101
100
@async
102
101
(. n ) => {
103
102
if n >= 0 && n < Array .length (tests ) {
104
- await (tests [n ](.))
105
- await (runAllTests (. n + 1 ))
103
+ @await
104
+ tests [n ](.)
105
+
106
+ @await
107
+ runAllTests (. n + 1 )
106
108
}
107
109
}
108
110
0 commit comments