Skip to content
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

add tests to check for the close event #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

daviddias
Copy link

@daviddias daviddias commented Jun 23, 2016

Hi @mafintosh!

I noticed today that the close event is not bubbled up from the underlying stream/socket to duplexify, in one of the sides, after a destroy is called. This seems truth for both 'destroying on the dialer' and 'destroy on the listener'. I made a couple of tests to show it.

It was kind of my expectation that the close event from the socket would bubble up in both sides, am I missing here anything or is this really a bug?

Thank you :)

@daviddias
Copy link
Author

daviddias commented Jun 23, 2016

Meanwhile, I've added the close propagation and fixed the close test

@mafintosh
Copy link
Owner

this one is kinda tricky because we are dealing with two streams and there is no guarantee that a stream will emit close.

just waiting for the readable one to emit close seems a bit hackish to me, although if we waited for both the readable and the writable there is a decent chance that one of the streams will never emit close.

thoughts?

@daviddias
Copy link
Author

daviddias commented Jul 8, 2016

Agreed, specially if the readable and the writable are not logically connected (i.e two different sockets). If duplexify is wrapping a socket, we also don't want to loose the socket feeling and stop emitting that 'close'.

💡 Idea: What if we add a 'socket' mode through an options object, making the 'close' event a thing that respects to its readable and writable side, so that then, when boith readable and writable emit 'close', 'close' is emitted, and if only one side 'emits', it waits for a timeout to force close the other side, (flushing first if it is force closing the writable).

@mafintosh
Copy link
Owner

I dont wanna add any timeout stuff to this module but to iterate your idea a bit i think a decent api would be.

Per default, if both the readable and writable has emitted close we emit close (or if destroy is called like it is now).

Add readableClose: false and writableClose: false options to disable waiting for close on either the readable or writable side.

@daviddias
Copy link
Author

That sound good to me :) 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants