Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changesStream suspend #408

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import { readFile } from 'fs/promises';
import { Application } from 'egg';
import { ChangesStreamService } from './app/core/service/ChangesStreamService';
declare module 'egg' {
interface Application {
binaryHTML: string;
Expand All @@ -26,10 +27,7 @@ export default class CnpmcoreAppHook {
// 应用退出时执行
// 需要暂停当前执行的 changesStream task
async beforeClose() {
await this.app.runInAnonymousContextScope(async ctx => {
await ctx.beginModuleScope(async () => {
await ctx.module.cnpmcoreCore.changesStreamService.suspendTaskWhenExit();
});
});
const changesStreamService = await this.app.getEggObject(ChangesStreamService);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@killagu egg 生命周期里面也可以注入 singleton 对象?

await changesStreamService.suspendTaskWhenExit();
}
}
5 changes: 0 additions & 5 deletions app/core/typing.ts

This file was deleted.