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;
|
return false;
|
||||||
},
|
},
|
||||||
timeout,
|
timeout,
|
||||||
abortDeferred.valueOrThrow()
|
abortDeferred
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1685,7 +1685,11 @@ export class Page extends EventEmitter {
|
|||||||
|
|
||||||
evaluate();
|
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 => {
|
r => {
|
||||||
cleanup();
|
cleanup();
|
||||||
return r;
|
return r;
|
||||||
|
@ -383,7 +383,7 @@ export async function waitForEvent<T>(
|
|||||||
eventName: string | symbol,
|
eventName: string | symbol,
|
||||||
predicate: (event: T) => Promise<boolean> | boolean,
|
predicate: (event: T) => Promise<boolean> | boolean,
|
||||||
timeout: number,
|
timeout: number,
|
||||||
abortPromise: Promise<Error>
|
abortPromise: Promise<Error> | Deferred<Error>
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const deferred = Deferred.create<T>({
|
const deferred = Deferred.create<T>({
|
||||||
message: `Timeout exceeded while waiting for event ${String(eventName)}`,
|
message: `Timeout exceeded while waiting for event ${String(eventName)}`,
|
||||||
|
@ -89,7 +89,9 @@ export class Deferred<T> {
|
|||||||
try {
|
try {
|
||||||
const promises = awaitables.map(value => {
|
const promises = awaitables.map(value => {
|
||||||
if (value instanceof Deferred) {
|
if (value instanceof Deferred) {
|
||||||
|
if (value.#timeoutId) {
|
||||||
deferredWithTimeout.add(value);
|
deferredWithTimeout.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
return value.valueOrThrow();
|
return value.valueOrThrow();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user