* Adding a close method for graceful shutdown

@ronkorving could you have a quick look? I will test it further with some of our tools in the next few hours.
What you could do is `if (this._onClose || this._isDestroyed) {`
and below on line 293, `this._onClose = null;` to clear it out.