Custom waitFor timeout error
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Error thrown when a waitFor timeout is reached
|
||||||
|
*/
|
||||||
|
export class WaitForTimeoutError extends Error {
|
||||||
|
constructor(type: string) {
|
||||||
|
super(`Timeout waiting for event "${type}"`);
|
||||||
|
this.name = 'WaitForTimeoutError';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { DeeplyReadonly } from './types.ts';
|
import type { DeeplyReadonly } from './types.ts';
|
||||||
|
|
||||||
|
import { WaitForTimeoutError } from './errors.ts';
|
||||||
import { deepFreeze } from './misc.ts';
|
import { deepFreeze } from './misc.ts';
|
||||||
|
|
||||||
export type EventMap = Record<string, unknown>;
|
export type EventMap = Record<string, unknown>;
|
||||||
@@ -213,7 +214,7 @@ export class EventEmitter<T extends EventMap> {
|
|||||||
if (timeoutMs !== undefined) {
|
if (timeoutMs !== undefined) {
|
||||||
timeoutId = setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
this.off(type, listener);
|
this.off(type, listener);
|
||||||
reject(new Error(`Timeout waiting for event "${String(type)}"`));
|
reject(new WaitForTimeoutError(String(type)));
|
||||||
}, timeoutMs);
|
}, timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user