required https://github.com/eggjs/egg/pull/5654 --------- Signed-off-by: MK (fengmk2) <fengmk2@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
20 lines
380 B
TypeScript
20 lines
380 B
TypeScript
|
|
import { Inject, ObjectInitType, type ContextEventBus } from 'egg';
|
|
import { Advice, type IAdvice } from 'egg/aop';
|
|
|
|
@Advice({
|
|
initType: ObjectInitType.CONTEXT,
|
|
})
|
|
export class EventCorkAdvice implements IAdvice {
|
|
@Inject()
|
|
private eventBus: ContextEventBus;
|
|
|
|
async beforeCall() {
|
|
this.eventBus.cork();
|
|
}
|
|
|
|
async afterFinally() {
|
|
this.eventBus.uncork();
|
|
}
|
|
}
|