Skip to content
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
4 changes: 2 additions & 2 deletions src/egg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ export class EggCore extends KoaApplication {
const singleton = new Singleton(options);
const initPromise = singleton.init();
if (initPromise) {
this.beforeStart(async () => {
this.lifecycle.registerBeforeStart(async () => {
await initPromise;
});
}, `${name}-singleton-init`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/singleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Singleton<T = any> {
createInstance(config: Record<string, any>, clientName: string) {
// async creator only support createInstanceAsync
assert(!isAsyncFunction(this.create),
`[@eggjs/core/singleton] ${this.name} only support synchronous creation, please use createInstanceAsync`);
`[@eggjs/core/singleton] ${this.name} only support asynchronous creation, please use createInstanceAsync`);
// options.default will be merge in to options.clients[id]
config = {
...this.options.default,
Expand Down
2 changes: 1 addition & 1 deletion test/singleton.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ describe('test/singleton.test.ts', () => {
assert(app.dataService instanceof Singleton);
await assert.rejects(async () => {
await app.dataService.createInstance({ foo1: 'bar1' });
}, /\[@eggjs\/core\/singleton\] dataService only support synchronous creation, please use createInstanceAsync$/);
}, /\[@eggjs\/core\/singleton\] dataService only support asynchronous creation, please use createInstanceAsync$/);
});

it('should return client name when create', async () => {
Expand Down