Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions apps/example/src/getTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1572,12 +1572,22 @@ export function getTests(
createTest('twoPromises can run in parallel', async () =>
(
await it(async () => {
const start = performance.now()
// 0.5s + 0.5s = ~1s in serial, ~0.5s in parallel
await Promise.all([testObject.wait(0.5), testObject.wait(0.5)])
const end = performance.now()
const didRunInParallel = end - start < 1000
return didRunInParallel
let started = 0
let release = () => {}
const bothStarted = new Promise<void>((resolve) => {
release = resolve
})
const onStarted = () => {
started++
if (started === 2) release()
return bothStarted
}
// Each native operation waits until both have invoked their callback.
await Promise.all([
testObject.callCallbackThatReturnsPromiseVoid(onStarted),
testObject.callCallbackThatReturnsPromiseVoid(onStarted),
])
return started === 2
})
)
.didNotThrow()
Expand Down
Loading