mirror of
https://github.com/directus/directus.git
synced 2026-01-29 20:38:04 -05:00
* Declare return types on functions And a very few other type related minor fixes * Minor syntax fixes * Remove unnecessary escape chars in regexes * Remove unnecessary awaits * Replace deprecated req.connection with req.socket * Replace deprecated upload with uploadOne * Remove unnecessary eslint-disable-next-line comments * Comment empty functions / catch or finally clauses * Fix irregular whitespaces * Add missing returns (null) * Remove unreachable code * A few logical fixes * Remove / Handle non-null assertions which are certainly unnecessary (e.g. in tests)
29 lines
654 B
TypeScript
29 lines
654 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) {
|
|
logger.warn(`An error was thrown while executing hook "${name}"`);
|
|
logger.warn(err);
|
|
}
|
|
return [];
|
|
}
|
|
|
|
export default emitter;
|