refactor: use p-defer

This commit is contained in:
Derrick Hammer 2023-04-19 23:29:49 -04:00
parent 6964c6bed2
commit a2055079d1
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 17 additions and 56 deletions

62
package-lock.json generated
View File

@ -30,15 +30,14 @@
"loady": "github:LumeWeb/loady",
"msgpackr": "^1.8.5",
"node-cache": "^5.1.2",
"node-cron": "^3.0.2",
"node-fetch": "^2.6.9",
"p-defer": "^4.0.0",
"p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git",
"pino": "^8.11.0",
"pino-pretty": "^9.4.0",
"promise-retry": "^2.0.1",
"protomux": "^3.4.1",
"protomux-rpc": "^1.3.0",
"random-access-memory": "^4.1.0",
"random-key": "^0.3.2",
"slugify": "^1.6.6",
"sodium-universal": "^4.0.0"
@ -4336,14 +4335,6 @@
"node": ">=8"
}
},
"node_modules/is-options": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-options/-/is-options-1.0.2.tgz",
"integrity": "sha512-u+Ai74c8Q74aS8BuHwPdI1jptGOT1FQXgCq8/zv0xRuE+wRgSMEJLj8lVO8Zp9BeGb29BXY6AsNPinfqjkr7Fg==",
"dependencies": {
"b4a": "^1.1.1"
}
},
"node_modules/is-plain-obj": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
@ -5405,17 +5396,6 @@
"node": ">= 8.0.0"
}
},
"node_modules/node-cron": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.2.tgz",
"integrity": "sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ==",
"dependencies": {
"uuid": "8.3.2"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
@ -8642,6 +8622,17 @@
"resolved": "https://registry.npmjs.org/ordered-object/-/ordered-object-0.2.3.tgz",
"integrity": "sha512-UKBtJiO7PsKqAAenewZ/moHQIRbcjZ4HE0J/+RyzgnpCTIn5ZLe3N2izno1kViTCXtHB4xuewjPgYLEiuS6t5A=="
},
"node_modules/p-defer": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/p-defer/-/p-defer-4.0.0.tgz",
"integrity": "sha512-Vb3QRvQ0Y5XnF40ZUWW7JfLogicVh/EnA5gBIvKDJoYpeI82+1E3AlB9yOcKFS0AhHrWVnAQO39fbR0G99IVEQ==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-each-series": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-each-series/-/p-each-series-3.0.0.tgz",
@ -9362,27 +9353,6 @@
"node": ">=8"
}
},
"node_modules/random-access-memory": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/random-access-memory/-/random-access-memory-4.1.0.tgz",
"integrity": "sha512-vVt75UQpWcaZWlysSmk7isqdhiV10WCovxuKZmBKg5zSsiEXIclJmAlIsMr8usYqfFmXzOGIonWOAyR5u3jhXQ==",
"dependencies": {
"b4a": "^1.1.0",
"inherits": "^2.0.3",
"is-options": "^1.0.1",
"random-access-storage": "^1.1.1"
}
},
"node_modules/random-access-storage": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/random-access-storage/-/random-access-storage-1.4.3.tgz",
"integrity": "sha512-D5e2iIC5dNENWyBxsjhEnNOMCwZZ64TARK6dyMN+3g4OTC4MJxyjh9hKLjTGoNhDOPrgjI+YlFEHFnrp/cSnzQ==",
"dependencies": {
"events": "^3.3.0",
"inherits": "^2.0.3",
"queue-tick": "^1.0.0"
}
},
"node_modules/random-key": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/random-key/-/random-key-0.3.2.tgz",
@ -10955,14 +10925,6 @@
"integrity": "sha512-mLs5zAK+ctllYBj+iAQvlDCwoxU/WDOUaJkcFudeiAX6OajC6BKXJUa9a+tbtkC11dz2Ufb7h0lyvIOVn4LADA==",
"dev": true
},
"node_modules/uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/validate-npm-package-license": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",

View File

@ -42,6 +42,7 @@
"msgpackr": "^1.8.5",
"node-cache": "^5.1.2",
"node-fetch": "^2.6.9",
"p-defer": "^4.0.0",
"p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git",
"pino": "^8.11.0",
"pino-pretty": "^9.4.0",

View File

@ -1,15 +1,13 @@
import { Plugin, PluginAPI } from "@lumeweb/interface-relay";
let pluginsLoadedResolve: () => void;
let pluginsLoadedPromise = new Promise<void>((resolve) => {
pluginsLoadedResolve = resolve;
});
import defer from "p-defer";
const plugin: Plugin = {
name: "core",
async plugin(api: PluginAPI): Promise<void> {
const pluginsLoaded = defer();
api.once("core.pluginsLoaded", () => {
pluginsLoadedResolve();
pluginsLoaded.resolve();
});
api.registerMethod("ping", {
@ -22,7 +20,7 @@ const plugin: Plugin = {
api.registerMethod("get_methods", {
cacheable: false,
async handler(): Promise<any> {
await pluginsLoadedPromise;
await pluginsLoaded.promise;
return api.rpcServer.getMethods();
},