*hook on core.pluginsLoaded to ensure that we don't answer until all plugins are loaded

This commit is contained in:
Derrick Hammer 2023-03-29 16:23:56 -04:00
parent 3600fbfdcf
commit 58e95806d0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 0 deletions

View File

@ -1,8 +1,17 @@
import { Plugin, PluginAPI } from "@lumeweb/relay-types"; import { Plugin, PluginAPI } from "@lumeweb/relay-types";
let pluginsLoadedResolve: () => void;
let pluginsLoadedPromise = new Promise<void>((resolve) => {
pluginsLoadedResolve = resolve;
});
const plugin: Plugin = { const plugin: Plugin = {
name: "core", name: "core",
async plugin(api: PluginAPI): Promise<void> { async plugin(api: PluginAPI): Promise<void> {
api.once("core.pluginsLoaded", () => {
pluginsLoadedResolve();
});
api.registerMethod("ping", { api.registerMethod("ping", {
cacheable: false, cacheable: false,
async handler(): Promise<any> { async handler(): Promise<any> {
@ -13,6 +22,10 @@ const plugin: Plugin = {
api.registerMethod("get_methods", { api.registerMethod("get_methods", {
cacheable: false, cacheable: false,
async handler(): Promise<any> { async handler(): Promise<any> {
await pluginsLoadedPromise;
console.log("get_methods", api.rpcServer.getMethods());
return api.rpcServer.getMethods(); return api.rpcServer.getMethods();
}, },
}); });