*Refactor setupStream, make it async, and await on ProtouxRPC ready when it exists in the browser

This commit is contained in:
Derrick Hammer 2023-04-08 14:37:13 -04:00
parent 788591b227
commit 8f7bd71e09
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 4 deletions

View File

@ -115,15 +115,19 @@ export function createHash(data: string): Buffer {
return hash; return hash;
} }
export function setupStream(stream: any) { export async function setupStream(stream: any) {
const existing = stream[RPC_PROTOCOL_SYMBOL]; const existing = stream[RPC_PROTOCOL_SYMBOL];
if (existing) { if (!existing) {
await existing._channel.ready;
return existing; return existing;
} }
stream[RPC_PROTOCOL_SYMBOL] = new RPC(stream); const rpc = new RPC(stream);
stream[RPC_PROTOCOL_SYMBOL] = rpc;
return stream[RPC_PROTOCOL_SYMBOL]; await existing.ready;
return rpc;
} }
export async function maybeGetAsyncProperty(object: any) { export async function maybeGetAsyncProperty(object: any) {