The dispose function calls the exit and delete functions, deletes all listeners, deletes all error handlers, and attempts to kill all domain members. The function checks if the domain has a parent, and if it does, it is removed from the domain. Then the domain is set to collect garbage and marked as located.
From the Node documentation:
Once the domain is deleted, the dispose event will occur.
I would delve into this topic, but the Node source is already beautifully annotated.
The timer you are talking about will be here where the domain members are repeated.
this.members.forEach(function(m) {
Here from Node source :
Domain.prototype.dispose = function() { if (this._disposed) return; // if we're the active domain, then get out now. this.exit(); this.emit('dispose'); // remove error handlers. this.removeAllListeners(); this.on('error', function() {}); // try to kill all the members. // XXX There should be more consistent ways // to shut down things! this.members.forEach(function(m) { // if it a timeout or interval, cancel it. clearTimeout(m); // drop all event listeners. if (m instanceof EventEmitter) { m.removeAllListeners(); // swallow errors m.on('error', function() {}); } // Be careful! // By definition, we're likely in error-ridden territory here, // so it quite possible that calling some of these methods // might cause additional exceptions to be thrown. endMethods.forEach(function(method) { if (typeof m[method] === 'function') { try { m[method](); } catch (er) {} } }); }); // remove from parent domain, if there is one. if (this.domain) this.domain.remove(this); // kill the references so that they can be properly gc'ed. this.members.length = 0; // finally, mark this domain as 'no longer relevant' // so that it can't be entered or activated. this._disposed = true; };
source share