protomux-rpc-client
Version:
Connect to protomux-rpc servers
22 lines (18 loc) • 491 B
JavaScript
module.exports = function waitForRPC (rpcClient) {
return new Promise((resolve, reject) => {
rpcClient.on('open', onopen)
rpcClient.on('destroy', ondestroy)
function onopen (handshake) {
removeListener()
resolve(handshake)
}
function ondestroy () {
removeListener()
reject(new Error('Client could not connect'))
}
function removeListener () {
rpcClient.off('open', onopen)
rpcClient.off('destroy', ondestroy)
}
})
}