From a92630172da2615073c92f0b75b7b0614ce465a3 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 4 Jul 2023 04:33:19 -0400 Subject: [PATCH] refactor: add ready getter that returns a promise hooked on the open event --- src/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.ts b/src/index.ts index d7350ee..e00a0fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,8 @@ import b4a from "b4a"; const ID = b4a.from("lumeweb"); export default class RPC extends ProtomuxRPC { + private _ready: Promise; + 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 { + return this._ready; + } }