fix: better debugging for WaitTask (#11330)

This commit is contained in:
Nikolay Vitkov 2023-11-09 11:38:27 +01:00 committed by GitHub
parent 2da4915e6b
commit d2480b022d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,6 +48,7 @@ export class WaitTask<T = unknown> {
#args: unknown[];
#timeout?: NodeJS.Timeout;
#timeoutError?: TimeoutError;
#result = Deferred.create<HandleFor<T>>();
@ -88,10 +89,11 @@ export class WaitTask<T = unknown> {
this.#world.taskManager.add(this);
if (options.timeout) {
this.#timeout = setTimeout(() => {
void this.terminate(
new TimeoutError(`Waiting failed: ${options.timeout}ms exceeded`)
this.#timeoutError = new TimeoutError(
`Waiting failed: ${options.timeout}ms exceeded`
);
this.#timeout = setTimeout(() => {
void this.terminate(this.#timeoutError);
}, options.timeout);
}
@ -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);
}
if (error && !this.#result.finished()) {
this.#result.reject(error);