diff --git a/apps/example/src/getTests.ts b/apps/example/src/getTests.ts index 0c698e436..d5a1c47e9 100644 --- a/apps/example/src/getTests.ts +++ b/apps/example/src/getTests.ts @@ -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((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()