Skip to content

Commit

Permalink
fix: wrap postMessage in timeout to prevent race conditions (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
AustP authored Mar 27, 2024
1 parent df5c425 commit 2d18482
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/clients/kibisis/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,15 @@ class KibisisClient extends BaseClient {
} as ResponseError<{ method: ProviderMethods }>)
}, timeout || DEFAULT_REQUEST_TIMEOUT)

// broadcast the request
channel.postMessage({
id: requestId,
params,
reference
} as RequestMessage<Params>)
// broadcast the request on the next tick
// this allows the channel to be ready before the request is sent
window.setTimeout(() => {
channel.postMessage({
id: requestId,
params,
reference
} as RequestMessage<Params>)
}, 0)
})
}

Expand Down

0 comments on commit 2d18482

Please sign in to comment.