Commit b2a0287b authored by nanahira's avatar nanahira

wait for async plugin load

parent 9339707b
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"@types/ws": "^8.2.0", "@types/ws": "^8.2.0",
"koa": "^2.13.3", "koa": "^2.13.3",
"koa-bodyparser": "^4.3.0", "koa-bodyparser": "^4.3.0",
"koishi-decorators": "^1.3.3", "koishi-decorators": "^1.3.4",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"typed-reflector": "^1.0.10", "typed-reflector": "^1.0.10",
"ws": "^8.2.3" "ws": "^8.2.3"
...@@ -5559,9 +5559,9 @@ ...@@ -5559,9 +5559,9 @@
} }
}, },
"node_modules/koishi-decorators": { "node_modules/koishi-decorators": {
"version": "1.3.3", "version": "1.3.4",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.3.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.4.tgz",
"integrity": "sha512-Q1iOHqG8p+qhRw2uzyZau8hb5+UGd8QaCdjpPaKc883nXhSAKksmsn0Nt/IrQDqEL4TKbsXKcTO1p59ukRO9Pg==", "integrity": "sha512-AokyzfDz3x4eZzd8AZrX+mVAGR7BBQdoyq1xAdol+48K2Ca7Xz8USu4Whvksi/tW8VrSN+Zr3L6YbCo3wS3fmg==",
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
...@@ -12192,9 +12192,9 @@ ...@@ -12192,9 +12192,9 @@
} }
}, },
"koishi-decorators": { "koishi-decorators": {
"version": "1.3.3", "version": "1.3.4",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.3.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.4.tgz",
"integrity": "sha512-Q1iOHqG8p+qhRw2uzyZau8hb5+UGd8QaCdjpPaKc883nXhSAKksmsn0Nt/IrQDqEL4TKbsXKcTO1p59ukRO9Pg==", "integrity": "sha512-AokyzfDz3x4eZzd8AZrX+mVAGR7BBQdoyq1xAdol+48K2Ca7Xz8USu4Whvksi/tW8VrSN+Zr3L6YbCo3wS3fmg==",
"requires": { "requires": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
......
...@@ -85,7 +85,7 @@ export class KoishiService ...@@ -85,7 +85,7 @@ export class KoishiService
} }
async onApplicationBootstrap() { async onApplicationBootstrap() {
this.metascan.registerContext(this.any()); await this.metascan.registerContext(this.any());
return this.start(); return this.start();
} }
......
...@@ -42,7 +42,7 @@ export class KoishiMetascanService { ...@@ -42,7 +42,7 @@ export class KoishiMetascanService {
return this.intercepterManager.addInterceptors(command, interceptorDefs); return this.intercepterManager.addInterceptors(command, interceptorDefs);
} }
private handleInstanceRegistration( private async handleInstanceRegistration(
ctx: Context, ctx: Context,
instance: Record<string, any>, instance: Record<string, any>,
methodKey: string, methodKey: string,
...@@ -69,6 +69,11 @@ export class KoishiMetascanService { ...@@ -69,6 +69,11 @@ export class KoishiMetascanService {
} }
}, true); }, true);
} }
} else if (result.type === 'plugin') {
const mayBePromise = result.result as Promise<any>;
if (mayBePromise instanceof Promise) {
await mayBePromise;
}
} }
} }
...@@ -156,15 +161,19 @@ export class KoishiMetascanService { ...@@ -156,15 +161,19 @@ export class KoishiMetascanService {
} }
registerContext(ctx: Context) { registerContext(ctx: Context) {
return this.runForEachProvider(ctx, (providerCtx, instance) => { return Promise.all(
this.scanInstanceForProvidingContextService(providerCtx, instance); this.runForEachProvider(ctx, (providerCtx, instance) => {
const registrar = new Registrar(instance); this.scanInstanceForProvidingContextService(providerCtx, instance);
registrar.performTopActions(providerCtx); const registrar = new Registrar(instance);
registrar registrar.performTopActions(providerCtx);
.getAllFieldsToRegister() return Promise.all(
.forEach((methodKey: string) => registrar
this.handleInstanceRegistration(providerCtx, instance, methodKey), .getAllFieldsToRegister()
.map((methodKey: string) =>
this.handleInstanceRegistration(providerCtx, instance, methodKey),
),
); );
}); }),
);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment