Skip to content

Commit

Permalink
fix: better debugging for WaitTask (#11330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Nov 9, 2023
1 parent 2da4915 commit d2480b0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/puppeteer-core/src/common/WaitTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class WaitTask<T = unknown> {
#args: unknown[];

#timeout?: NodeJS.Timeout;
#timeoutError?: TimeoutError;

#result = Deferred.create<HandleFor<T>>();

Expand Down Expand Up @@ -88,10 +89,11 @@ export class WaitTask<T = unknown> {
this.#world.taskManager.add(this);

if (options.timeout) {
this.#timeoutError = new TimeoutError(
`Waiting failed: ${options.timeout}ms exceeded`
);
this.#timeout = setTimeout(() => {
void this.terminate(
new TimeoutError(`Waiting failed: ${options.timeout}ms exceeded`)
);
void this.terminate(this.#timeoutError);
}, options.timeout);
}

Expand Down Expand Up @@ -184,9 +186,7 @@ export class WaitTask<T = unknown> {
async terminate(error?: Error): Promise<void> {
this.#world.taskManager.delete(this);

if (this.#timeout) {
clearTimeout(this.#timeout);
}
clearTimeout(this.#timeout);

if (error && !this.#result.finished()) {
this.#result.reject(error);
Expand Down

0 comments on commit d2480b0

Please sign in to comment.