*Refactor setupStream, make it async, and await on ProtouxRPC ready when it exists in the browser
This commit is contained in:
parent
788591b227
commit
8f7bd71e09
12
src/util.ts
12
src/util.ts
|
@ -115,15 +115,19 @@ export function createHash(data: string): Buffer {
|
|||
return hash;
|
||||
}
|
||||
|
||||
export function setupStream(stream: any) {
|
||||
export async function setupStream(stream: any) {
|
||||
const existing = stream[RPC_PROTOCOL_SYMBOL];
|
||||
if (existing) {
|
||||
if (!existing) {
|
||||
await existing._channel.ready;
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue