Handle errors in Predicate function

This commit is contained in:
2026-08-07 02:12:09 +00:00
parent ede4c54252
commit c919728fb3
2 changed files with 26 additions and 1 deletions
+8 -1
View File
@@ -181,7 +181,12 @@ export class EventEmitter<T extends EventMap> {
// Create a listener function.
const listener = (payload: Readonly<T[K]>): void => {
if (predicate(payload)) {
try {
// If the event payload does not match the predicate condition, return.
if (!predicate(payload)) {
return;
}
// Clean up
this.off(type, listener);
if (timeoutId !== undefined) {
@@ -189,6 +194,8 @@ export class EventEmitter<T extends EventMap> {
}
resolve(payload);
} catch (error) {
reject(error);
}
};