From cba249cbcdf14694d6ba71d999d04ca41701a711 Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 8 Sep 2020 13:34:30 +0800 Subject: [PATCH] fix: import/cycle --- packages/hydrooj/src/service/bus.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/hydrooj/src/service/bus.ts b/packages/hydrooj/src/service/bus.ts index 315308381..240e05cd0 100644 --- a/packages/hydrooj/src/service/bus.ts +++ b/packages/hydrooj/src/service/bus.ts @@ -3,9 +3,8 @@ import cluster from 'cluster'; import { Db, UpdateQuery } from 'mongodb'; import { Logger } from '../logger'; import { Mdoc, Rdoc, User } from '../interface'; -// only typings. -// eslint-disable-next-line import/no-cycle -import { DocType } from '../model/document'; + +type DocType = import('../model/document').DocType; const _hooks: Record any>> = {}; const logger = new Logger('bus', true); @@ -91,15 +90,17 @@ export function emit(name: K, ...args: Parameters(name: K, ...args: Parameters): Promise { - logger.debug('serial: %s', name, args); - const hooks = Array.from(_hooks[name]); + logger.debug('serial: %s %o', name, args); + const hooks = Array.from(_hooks[name] || []); for (const callback of hooks) { await callback.apply(this, args); } } export function bail(name: K, ...args: Parameters): ReturnType { - for (const callback of _hooks[name] || []) { + logger.debug('bail: %s %o', name, args); + const hooks = Array.from(_hooks[name] || []); + for (const callback of hooks) { const result = callback.apply(this, args); if (isBailed(result)) return result; }