Created
January 25, 2023 12:46
-
-
Save rowend36/e064e89d8733a022b44b472a4bfa8550 to your computer and use it in GitHub Desktop.
Simulate callback handling for OpenRPC websockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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