Handle errors in Predicate function
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user