Make destroySoon behave better.

Wait for the buffer to empty before closing the socket.
Package for npm.