refactor: add ready getter that returns a promise hooked on the open event
This commit is contained in:
parent
d0f2c04819
commit
a92630172d
10
src/index.ts
10
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<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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue