From 91649558a8b36a8796574cea7e33d496a0954a0c Mon Sep 17 00:00:00 2001 From: Harvmaster Date: Mon, 10 Aug 2026 01:58:37 +0000 Subject: [PATCH] Custom waitFor timeout error --- source/errors.ts | 10 ++++++++++ source/event-emitter.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/errors.ts b/source/errors.ts index b4de714..f018d0a 100644 --- a/source/errors.ts +++ b/source/errors.ts @@ -80,3 +80,13 @@ export class ExponentialBackoffNonIntegerError extends Error { this.name = 'ExponentialBackoffNonIntegerError'; } } + +/** + * 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'; + } +} diff --git a/source/event-emitter.ts b/source/event-emitter.ts index 6e4fc26..ccc0dd5 100644 --- a/source/event-emitter.ts +++ b/source/event-emitter.ts @@ -1,5 +1,6 @@ import type { DeeplyReadonly } from './types.ts'; +import { WaitForTimeoutError } from './errors.ts'; import { deepFreeze } from './misc.ts'; export type EventMap = Record; @@ -213,7 +214,7 @@ export class EventEmitter { if (timeoutMs !== undefined) { timeoutId = setTimeout(() => { this.off(type, listener); - reject(new Error(`Timeout waiting for event "${String(type)}"`)); + reject(new WaitForTimeoutError(String(type))); }, timeoutMs); }