Files
directus/api/src/emitter.ts
Nicola Krumschmidt d64ca14348 Explicitly set catch parameters to any type (#7654)
This fixes not being able to build the repo due to type issues
introduced by the Typescript 4.4 option "useUnknownInCatchVariables",
which is enabled by default in strict mode.
2021-08-27 10:33:30 -04:00

29 lines
659 B
TypeScript

import { EventEmitter2 } from 'eventemitter2';
import logger from './logger';
const emitter = new EventEmitter2({
wildcard: true,
verboseMemoryLeak: true,
delimiter: '.',
// This will ignore the "unspecified event" error
ignoreErrors: true,
});
/**
* Emit async events without throwing errors. Just log them out as warnings.
* @param name
* @param args
*/
export async function emitAsyncSafe(name: string, ...args: any[]): Promise<any> {
try {
return await emitter.emitAsync(name, ...args);
} catch (err: any) {
logger.warn(`An error was thrown while executing hook "${name}"`);
logger.warn(err);
}
return [];
}
export default emitter;