Skip to content

Commit 5d9aa13

Browse files
committed
Exercise await on JSPromise/value
1 parent 79772bd commit 5d9aa13

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Examples/EmbeddedConcurrency/Sources/EmbeddedConcurrencyApp/App.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,36 @@ struct App {
121121
check(false, "Promise chaining should succeed")
122122
}
123123

124+
// Test 7: JSPromise.value await (with async resolution)
125+
let promise2 = JSPromise(resolver: { resolve in
126+
_ = JSObject.global.setTimeout!(
127+
JSOneshotClosure { _ in
128+
resolve(.success(JSValue.number(456)))
129+
return .undefined
130+
},
131+
1
132+
)
133+
})
134+
let awaitedValue = try await promise2.value
135+
check(awaitedValue.number == 456, "JSPromise.value await returns correct value")
136+
137+
// Test 8: JSPromise.result await (with async resolution)
138+
let promise3 = JSPromise(resolver: { resolve in
139+
_ = JSObject.global.setTimeout!(
140+
JSOneshotClosure { _ in
141+
resolve(.success(JSValue.number(789)))
142+
return .undefined
143+
},
144+
1
145+
)
146+
})
147+
let awaitedResult = await promise3.result
148+
if case .success(let val) = awaitedResult {
149+
check(val.number == 789, "JSPromise.result await resolves correctly")
150+
} else {
151+
check(false, "JSPromise.result await should succeed")
152+
}
153+
124154
// Summary
125155
let console = JSObject.global.console
126156
let totalTests = testsPassed + testsFailed

Examples/EmbeddedConcurrency/run.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { instantiate } from
33
import { defaultNodeSetup } from
44
"./.build/plugins/PackageToJS/outputs/Package/platforms/node.js"
55

6-
const EXPECTED_TESTS = 6;
6+
const EXPECTED_TESTS = 8;
77
const TIMEOUT_MS = 30_000;
88

99
// Intercept console.log to capture test output

0 commit comments

Comments
 (0)