fix: WaitForNetworkIdle and Deferred.race (#10411)

This commit is contained in:
Nikolay Vitkov 2023-06-19 10:11:59 +02:00 committed by GitHub
parent a147488e5a
commit 138cc5c961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -1673,7 +1673,7 @@ export class Page extends EventEmitter {
return false;
},
timeout,
abortDeferred.valueOrThrow()
abortDeferred
);
};
@ -1685,7 +1685,11 @@ export class Page extends EventEmitter {
evaluate();
await Deferred.race([idleDeferred, ...eventPromises, closedDeferred]).then(
// We don't want to reject the closed deferred when
// the race if finished so we pass the Promise instead
const closedPromise = closedDeferred.valueOrThrow();
await Deferred.race([idleDeferred, ...eventPromises, closedPromise]).then(
r => {
cleanup();
return r;

View File

@ -383,7 +383,7 @@ export async function waitForEvent<T>(
eventName: string | symbol,
predicate: (event: T) => Promise<boolean> | boolean,
timeout: number,
abortPromise: Promise<Error>
abortPromise: Promise<Error> | Deferred<Error>
): Promise<T> {
const deferred = Deferred.create<T>({
message: `Timeout exceeded while waiting for event ${String(eventName)}`,

View File

@ -89,7 +89,9 @@ export class Deferred<T> {
try {
const promises = awaitables.map(value => {
if (value instanceof Deferred) {
deferredWithTimeout.add(value);
if (value.#timeoutId) {
deferredWithTimeout.add(value);
}
return value.valueOrThrow();
}