Commit b2a0287b authored by nanahira's avatar nanahira

wait for async plugin load

parent 9339707b
......@@ -14,7 +14,7 @@
"@types/ws": "^8.2.0",
"koa": "^2.13.3",
"koa-bodyparser": "^4.3.0",
"koishi-decorators": "^1.3.3",
"koishi-decorators": "^1.3.4",
"lodash": "^4.17.21",
"typed-reflector": "^1.0.10",
"ws": "^8.2.3"
......@@ -5559,9 +5559,9 @@
}
},
"node_modules/koishi-decorators": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.3.tgz",
"integrity": "sha512-Q1iOHqG8p+qhRw2uzyZau8hb5+UGd8QaCdjpPaKc883nXhSAKksmsn0Nt/IrQDqEL4TKbsXKcTO1p59ukRO9Pg==",
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.4.tgz",
"integrity": "sha512-AokyzfDz3x4eZzd8AZrX+mVAGR7BBQdoyq1xAdol+48K2Ca7Xz8USu4Whvksi/tW8VrSN+Zr3L6YbCo3wS3fmg==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
......@@ -12192,9 +12192,9 @@
}
},
"koishi-decorators": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.3.tgz",
"integrity": "sha512-Q1iOHqG8p+qhRw2uzyZau8hb5+UGd8QaCdjpPaKc883nXhSAKksmsn0Nt/IrQDqEL4TKbsXKcTO1p59ukRO9Pg==",
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.4.tgz",
"integrity": "sha512-AokyzfDz3x4eZzd8AZrX+mVAGR7BBQdoyq1xAdol+48K2Ca7Xz8USu4Whvksi/tW8VrSN+Zr3L6YbCo3wS3fmg==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
......
......@@ -85,7 +85,7 @@ export class KoishiService
}
async onApplicationBootstrap() {
this.metascan.registerContext(this.any());
await this.metascan.registerContext(this.any());
return this.start();
}
......
......@@ -42,7 +42,7 @@ export class KoishiMetascanService {
return this.intercepterManager.addInterceptors(command, interceptorDefs);
}
private handleInstanceRegistration(
private async handleInstanceRegistration(
ctx: Context,
instance: Record<string, any>,
methodKey: string,
......@@ -69,6 +69,11 @@ export class KoishiMetascanService {
}
}, 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 {
}
registerContext(ctx: Context) {
return this.runForEachProvider(ctx, (providerCtx, instance) => {
this.scanInstanceForProvidingContextService(providerCtx, instance);
const registrar = new Registrar(instance);
registrar.performTopActions(providerCtx);
registrar
.getAllFieldsToRegister()
.forEach((methodKey: string) =>
this.handleInstanceRegistration(providerCtx, instance, methodKey),
return Promise.all(
this.runForEachProvider(ctx, (providerCtx, instance) => {
this.scanInstanceForProvidingContextService(providerCtx, instance);
const registrar = new Registrar(instance);
registrar.performTopActions(providerCtx);
return Promise.all(
registrar
.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