events: cache domain module locally

It's faster than calling `require` every time we create an
`EventEmitter`.
This commit is contained in:
Maciej Małecki 2012-06-17 11:50:40 +02:00 committed by isaacs
parent 71a2a2caa6
commit 3db2e034c4

View File

@ -20,11 +20,12 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var isArray = Array.isArray;
var domain;
function EventEmitter() {
if (exports.usingDomains) {
// if there is an active domain, then attach to it.
var domain = require('domain');
domain = domain || require('domain');
if (domain.active && !(this instanceof domain.Domain)) {
this.domain = domain.active;
}