Skip to content

Instantly share code, notes, and snippets.

@rowend36
Created January 25, 2023 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowend36/e064e89d8733a022b44b472a4bfa8550 to your computer and use it in GitHub Desktop.
Save rowend36/e064e89d8733a022b44b472a4bfa8550 to your computer and use it in GitHub Desktop.
Simulate callback handling for OpenRPC websockets
var conn = this.socket.connection;
conn.send(
JSON.stringify({
jsonrpc: '2.0',
method: method,
params: params,
})
);
if (cb) {
//The notify promise does not resolve on all browsers
//so we resort to polling
setTimeout(function () {
if (conn.bufferedAmount < 1) cb();
else
var a = setInterval(function () {
if (conn.bufferedAmount < 1) {
clearInterval(a);
cb();
}
}, 25);
}, 500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment