mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: WaitForNetworkIdle and Deferred.race (#10411)
This commit is contained in:
parent
a147488e5a
commit
138cc5c961
@ -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;
|
||||
|
@ -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)}`,
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user