Skip to content

Commit d86814a

Browse files
othiym23isaacs
authored andcommitted
domains: deprecate domain.dispose().
Follows @isaacs's recommendations in nodejs/node-v0.x-archive#5018. Includes some updates to documentation but not examples. Conflicts: lib/domain.js
1 parent 645418e commit d86814a

File tree

2 files changed

+9
-56
lines changed

2 files changed

+9
-56
lines changed

doc/api/domain.markdown

+6-16
Original file line numberDiff line numberDiff line change
@@ -420,21 +420,11 @@ without exiting the domain.
420420

421421
### domain.dispose()
422422

423-
The dispose method destroys a domain, and makes a best effort attempt to
424-
clean up any and all IO that is associated with the domain. Streams are
425-
aborted, ended, closed, and/or destroyed. Timers are cleared.
426-
Explicitly bound callbacks are no longer called. Any error events that
427-
are raised as a result of this are ignored.
428-
429-
The intention of calling `dispose` is generally to prevent cascading
430-
errors when a critical part of the Domain context is found to be in an
431-
error state.
432-
433-
Once the domain is disposed the `dispose` event will emit.
434-
435-
Note that IO might still be performed. However, to the highest degree
436-
possible, once a domain is disposed, further errors from the emitters in
437-
that set will be ignored. So, even if some remaining actions are still
438-
in flight, Node.js will not communicate further about them.
423+
Stability: 0 - Deprecated. Please recover from failed IO actions
424+
explicitly via error event handlers set on the domain.
425+
426+
Once `dispose` has been called, the domain will no longer be used by callbacks
427+
bound into the domain via `run`, `bind`, or `intercept`, and a `dispose` event
428+
is emitted.
439429

440430
[EventEmitter]: events.html#events_class_events_eventemitter

lib/domain.js

+3-40
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ var events = require('events');
2424
var EventEmitter = events.EventEmitter;
2525
var inherits = util.inherits;
2626

27-
// methods that are called when trying to shut down explicitly bound EEs
28-
var endMethods = ['end', 'abort', 'destroy', 'destroySoon'];
29-
3027
// communicate with events module, but don't require that
3128
// module to have to load this one, since this module has
3229
// a few side effects.
@@ -259,53 +256,19 @@ Domain.prototype.bind = function(cb, interceptError) {
259256
return b;
260257
};
261258

262-
Domain.prototype.dispose = function() {
259+
Domain.prototype.dispose = util.deprecate(function() {
263260
if (this._disposed) return;
264261

265262
// if we're the active domain, then get out now.
266263
this.exit();
267264

268-
this.emit('dispose');
269-
270-
// remove error handlers.
271-
this.removeAllListeners();
272-
this.on('error', function() {});
273-
274-
// try to kill all the members.
275-
// XXX There should be more consistent ways
276-
// to shut down things!
277-
this.members.forEach(function(m) {
278-
// if it's a timeout or interval, cancel it.
279-
clearTimeout(m);
280-
281-
// drop all event listeners.
282-
if (m instanceof EventEmitter) {
283-
m.removeAllListeners();
284-
// swallow errors
285-
m.on('error', function() {});
286-
}
287-
288-
// Be careful!
289-
// By definition, we're likely in error-ridden territory here,
290-
// so it's quite possible that calling some of these methods
291-
// might cause additional exceptions to be thrown.
292-
endMethods.forEach(function(method) {
293-
if (util.isFunction(m[method])) {
294-
try {
295-
m[method]();
296-
} catch (er) {}
297-
}
298-
});
299-
300-
});
301-
302265
// remove from parent domain, if there is one.
303266
if (this.domain) this.domain.remove(this);
304267

305268
// kill the references so that they can be properly gc'ed.
306269
this.members.length = 0;
307270

308-
// finally, mark this domain as 'no longer relevant'
271+
// mark this domain as 'no longer relevant'
309272
// so that it can't be entered or activated.
310273
this._disposed = true;
311-
};
274+
});

0 commit comments

Comments
 (0)