File tree 2 files changed +20
-0
lines changed
IntegrationTests/TestSuites/Sources/ConcurrencyTests
Sources/JavaScriptEventLoop
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ func entrypoint() async throws {
32
32
resolve ( . success( 1 ) )
33
33
} )
34
34
try await expectEqual ( p. value, 1 )
35
+ try await expectEqual ( p. result, . success( . number( 1 ) ) )
35
36
}
36
37
37
38
try await asyncTest ( " await rejected Promise " ) {
@@ -41,6 +42,7 @@ func entrypoint() async throws {
41
42
let error = try await expectAsyncThrow ( await p. value)
42
43
let jsValue = try expectCast ( error, to: JSValue . self)
43
44
try expectEqual ( jsValue, 3 )
45
+ try await expectEqual ( p. result, . failure( . number( 3 ) ) )
44
46
}
45
47
46
48
try await asyncTest ( " Continuation " ) {
Original file line number Diff line number Diff line change @@ -116,6 +116,24 @@ public extension JSPromise {
116
116
}
117
117
}
118
118
}
119
+
120
+ /// Wait for the promise to complete, returning its result or exception as a Result.
121
+ var result : Result < JSValue , JSValue > {
122
+ get async {
123
+ await withUnsafeContinuation { [ self ] continuation in
124
+ self . then (
125
+ success: {
126
+ continuation. resume ( returning: . success( $0) )
127
+ return JSValue . undefined
128
+ } ,
129
+ failure: {
130
+ continuation. resume ( returning: . failure( $0) )
131
+ return JSValue . undefined
132
+ }
133
+ )
134
+ }
135
+ }
136
+ }
119
137
}
120
138
121
139
#endif
You can’t perform that action at this time.
0 commit comments