-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you know when the stream ends? #19
Comments
pull-goodbye is already used in muxrpc https://github.com/ssbc/muxrpc/blob/master/stream.js#L99-L101 are you getting a ws stream that ends and muxrpc doesn't realize? |
hmm. I'm not sure where to get a cb for the end event. We have a normal situation on the server like: ws({ server: server }, function onWsConnect (wsStream) {
pull( myService, wsStream, myService )
}) Thanks |
A through stream like this works. Is this a good way to do it? function OnEnd (cb) {
return function sink (read) {
return function source (abort, _cb) {
if (abort) {
console.log('abort', abort)
cb()
}
read(abort, function onNext (end, data) {
if (end === true) cb()
_cb(end, data)
})
}
}
} |
one way is that createServer(function (stream) {
var serverRPC = MRPC(null, api) ({
hello: function (name, cb) {
cb(null, 'hello, ' + name + '!')
} //etc...
})
var serverStream = serverRPC.createStream(function callback (err) {
//this is called when the connection ends
})
pull(stream, serverStream, stream) //pipe together
}) note, that when the stream ends, you can create another stream and keep that rpc object, which you might want to do on client objects, but not servers. |
ah, also the |
Thanks @dominictarr ! I went ahead and submitted a PR in muxrpc to add those to the readme. |
How do you tell when a ws connection closes if you are using pull-ws and muxrpc? I see pull-goodbye but I'm not sure how to use it.
The text was updated successfully, but these errors were encountered: