How to use the events.usingDomains function in events

To help you get started, we’ve selected a few events examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github restify / errors / lib / serializer.js View on Github external
var self = this;
    var ret = '';

    // look for error context in 3 places, in ascending order of precedence:
    // 1) raw fields on the error object that are not known verror or
    // restify-error fields
    // 2) restify-error context fields (restify-errors@ <= 5.x)
    // 3) verror info field
    var topLevelFields = (self._serializeTopLevelFields === true) ?
        _.omit(err, self._knownFields) :
        {};

    // We don't want to load domains just to check if topLevelFields.domain is
    // a Domain instance, so first we make sure domains are already loaded.
    if (EventEmitter.usingDomains) {
        if (!domain) {
            // eslint-disable-next-line global-require
            domain = require('domain');
        }

        if (topLevelFields.domain instanceof domain.Domain) {
            topLevelFields = _.omit(topLevelFields, [ 'domain' ]);
        }
    }

    // combine all fields into a pojo, and serialize
    var allFields = _.assign({}, topLevelFields, err.context, nerror.info(err));

    if (!_.isEmpty(allFields)) {
        ret = ' (' + serializeIntoEqualString(allFields) + ')';
    }
github graalvm / graaljs / lib / domain.js View on Github external
function runBound() {
    return bound(this, self, cb, arguments);
  }

  Object.defineProperty(runBound, 'domain', {
    configurable: true,
    enumerable: false,
    value: this,
    writable: true
  });

  return runBound;
};

// Override EventEmitter methods to make it domain-aware.
EventEmitter.usingDomains = true;

const eventInit = EventEmitter.init;
EventEmitter.init = function() {
  Object.defineProperty(this, 'domain', {
    configurable: true,
    enumerable: false,
    value: null,
    writable: true
  });
  if (exports.active && !(this instanceof exports.Domain)) {
    this.domain = exports.active;
  }

  return eventInit.call(this);
};
github apigee / trireme / node10 / node10src / src / main / javascript / io / apigee / trireme / node10 / node / domain.js View on Github external
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var util = require('util');
var events = require('events');
var EventEmitter = events.EventEmitter;
var inherits = util.inherits;

// methods that are called when trying to shut down expliclitly bound EEs
var endMethods = ['end', 'abort', 'destroy', 'destroySoon'];

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
events.usingDomains = true;

// let the process know we're using domains
process._usingDomains();

exports.Domain = Domain;

exports.create = exports.createDomain = function(cb) {
  return new Domain(cb);
};

// it's possible to enter one domain while already inside
// another one.  the stack is each entered domain.
var stack = [];
exports._stack = stack;
// the active domain is always the one that we're currently in.
exports.active = null;
github apigee / trireme / node12 / node12src / src / main / javascript / io / apigee / trireme / node12 / node / domain.js View on Github external
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var util = require('util');
var EventEmitter = require('events');
var inherits = util.inherits;

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
EventEmitter.usingDomains = true;

// overwrite process.domain with a getter/setter that will allow for more
// effective optimizations
var _domain = [null];
Object.defineProperty(process, 'domain', {
  enumerable: true,
  get: function() {
    return _domain[0];
  },
  set: function(arg) {
    return _domain[0] = arg;
  }
});

// objects with external array data are excellent ways to communicate state
// between js and c++ w/o much overhead
github nodekit-io / nodekit-darwin / src / nodekit / NKCore / lib-core / node / domain.js View on Github external
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var util = require('util');
var EventEmitter = require('events');
var inherits = util.inherits;

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
EventEmitter.usingDomains = true;

// overwrite process.domain with a getter/setter that will allow for more
// effective optimizations
var _domain = [null];
Object.defineProperty(process, 'domain', {
  enumerable: true,
  get: function() {
    return _domain[0];
  },
  set: function(arg) {
    return _domain[0] = arg;
  }
});

// objects with external array data are excellent ways to communicate state
// between js and c++ w/o much overhead
github ILIAS-eLearning / ILIAS / Modules / Chatroom / chat / node_modules / mysql / lib / Connection.js View on Github external
return function () {
    if (Events.usingDomains && ee.domain) {
      ee.domain.enter();
      fn.apply(this, arguments);
      ee.domain.exit();
    } else {
      fn.apply(this, arguments);
    }
  };
}
github mysqljs / mysql / lib / Connection.js View on Github external
return function () {
    if (Events.usingDomains && ee.domain) {
      ee.domain.enter();
      fn.apply(this, arguments);
      ee.domain.exit();
    } else {
      fn.apply(this, arguments);
    }
  };
}
github andrewshawcare / thoughtworks-email-signature-generator / node_modules / grunt-aws / node_modules / aws-sdk / lib / sequential_executor.js View on Github external
constructor: function SequentialExecutor() {
    this.domain = null;
    if (require('events').usingDomains) {
      domain = require('domain');
      if (domain.active) this.domain = domain.active;
    }
    this._events = {};
  },
github graalvm / graaljs / deps / npm / node_modules / request / node_modules / har-validator / node_modules / bluebird / js / main / async.js View on Github external
}
};

Async.prototype._getDomain = function() {};

if (!false) {
if (util.isNode) {
    var EventsModule = require("events");

    var domainGetter = function() {
        var domain = process.domain;
        if (domain === null) return undefined;
        return domain;
    };

    if (EventsModule.usingDomains) {
        Async.prototype._getDomain = domainGetter;
    } else {
        var descriptor =
            Object.getOwnPropertyDescriptor(EventsModule, "usingDomains");

        if (descriptor) {
            if (!descriptor.configurable) {
                process.on("domainsActivated", function() {
                    Async.prototype._getDomain = domainGetter;
                });
            } else {
                var usingDomains = false;
                Object.defineProperty(EventsModule, "usingDomains", {
                    configurable: false,
                    enumerable: true,
                    get: function() {
github DiedB / Homey-SolarPanels / node_modules / request / node_modules / har-validator / node_modules / bluebird / js / main / async.js View on Github external
}
};

Async.prototype._getDomain = function() {};

if (!false) {
if (util.isNode) {
    var EventsModule = require("events");

    var domainGetter = function() {
        var domain = process.domain;
        if (domain === null) return undefined;
        return domain;
    };

    if (EventsModule.usingDomains) {
        Async.prototype._getDomain = domainGetter;
    } else {
        var descriptor =
            Object.getOwnPropertyDescriptor(EventsModule, "usingDomains");

        if (descriptor) {
            if (!descriptor.configurable) {
                process.on("domainsActivated", function() {
                    Async.prototype._getDomain = domainGetter;
                });
            } else {
                var usingDomains = false;
                Object.defineProperty(EventsModule, "usingDomains", {
                    configurable: false,
                    enumerable: true,
                    get: function() {