mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fix: import/cycle
This commit is contained in:
1 parent
3e721fdd55
commit
cba249cbcd
1 file changed
+7
-6
@@ -3,9 +3,8 @@ import cluster from 'cluster';
|
|||||||
import { Db, UpdateQuery } from 'mongodb';
|
import { Db, UpdateQuery } from 'mongodb';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { Mdoc, Rdoc, User } from '../interface';
|
import { Mdoc, Rdoc, User } from '../interface';
|
||||||
// only typings.
|
|
||||||
// eslint-disable-next-line import/no-cycle
|
type DocType = import('../model/document').DocType;
|
||||||
import { DocType } from '../model/document';
|
|
||||||
|
|
||||||
const _hooks: Record<keyof any, Array<(...args: any[]) => any>> = {};
|
const _hooks: Record<keyof any, Array<(...args: any[]) => any>> = {};
|
||||||
const logger = new Logger('bus', true);
|
const logger = new Logger('bus', true);
|
||||||
@@ -91,15 +90,17 @@ export function emit<K extends keyof EventMap>(name: K, ...args: Parameters<Even
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function serial<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): Promise<void> {
|
export async function serial<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): Promise<void> {
|
||||||
logger.debug('serial: %s', name, args);
|
logger.debug('serial: %s %o', name, args);
|
||||||
const hooks = Array.from(_hooks[name]);
|
const hooks = Array.from(_hooks[name] || []);
|
||||||
for (const callback of hooks) {
|
for (const callback of hooks) {
|
||||||
await callback.apply(this, args);
|
await callback.apply(this, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bail<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): ReturnType<EventMap[K]> {
|
export function bail<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): ReturnType<EventMap[K]> {
|
||||||
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);
|
const result = callback.apply(this, args);
|
||||||
if (isBailed(result)) return result;
|
if (isBailed(result)) return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user