refactor: add ready getter that returns a promise hooked on the open event

This commit is contained in:
Derrick Hammer 2023-07-04 04:33:19 -04:00
parent d0f2c04819
commit a92630172d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import b4a from "b4a";
const ID = b4a.from("lumeweb");
export default class RPC extends ProtomuxRPC {
private _ready: Promise<void>;
constructor(stream: any, options = {}) {
options = {
...{
@ -15,9 +17,17 @@ export default class RPC extends ProtomuxRPC {
...options,
};
super(stream, options);
this._ready = new Promise((resolve) => {
// @ts-ignore
this.on("open", resolve);
});
}
async request(method: any, value: any | string = "", options = {}) {
return super.request(method, value, options);
}
get ready(): Promise<void> {
return this._ready;
}
}