How to use the events.listenerCount 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 graalvm / graaljs / lib / domain.js View on Github external
// The top-level domain-handler is handled separately.
  //
  // The reason is that if V8 was passed a command line option
  // asking it to abort on an uncaught exception (currently
  // "--abort-on-uncaught-exception"), we want an uncaught exception
  // in the top-level domain error handler to make the
  // process abort. Using try/catch here would always make V8 think
  // that these exceptions are caught, and thus would prevent it from
  // aborting in these cases.
  if (stack.length === 1) {
    // If there's no error handler, do not emit an 'error' event
    // as this would throw an error, make the process exit, and thus
    // prevent the process 'uncaughtException' event from being emitted
    // if a listener is set.
    if (EventEmitter.listenerCount(this, 'error') > 0) {
      // Clear the uncaughtExceptionCaptureCallback so that we know that, even
      // if technically the top-level domain is still active, it would
      // be ok to abort on an uncaught exception at this point
      setUncaughtExceptionCaptureCallback(null);
      try {
        caught = this.emit('error', er);
      } finally {
        updateExceptionCapture();
      }
    }
  } else {
    // Wrap this in a try/catch so we don't get infinite throwing
    try {
      // One of three things will happen here.
      //
      // 1. There is a handler, caught = true
github zhukovaskychina / X-Nodejs / X-Node / node-v10.15.3 / lib / domain.js View on Github external
// The top-level domain-handler is handled separately.
  //
  // The reason is that if V8 was passed a command line option
  // asking it to abort on an uncaught exception (currently
  // "--abort-on-uncaught-exception"), we want an uncaught exception
  // in the top-level domain error handler to make the
  // process abort. Using try/catch here would always make V8 think
  // that these exceptions are caught, and thus would prevent it from
  // aborting in these cases.
  if (stack.length === 1) {
    // If there's no error handler, do not emit an 'error' event
    // as this would throw an error, make the process exit, and thus
    // prevent the process 'uncaughtException' event from being emitted
    // if a listener is set.

    if (EventEmitter.listenerCount(this, 'error') > 0) {
      // Clear the uncaughtExceptionCaptureCallback so that we know that, even
      // if technically the top-level domain is still active, it would
      // be ok to abort on an uncaught exception at this point
      setUncaughtExceptionCaptureCallback(null);
      try {
        caught = this.emit('error', er);
      } finally {
        updateExceptionCapture();
      }
    }
  } else {
    // wrap this in a try/catch so we don't get infinite throwing
    try {
      // One of three things will happen here.
      //
      // 1. There is a handler, caught = true
github lionsharecapital / lionshare-desktop / src / scenes / Portfolio / PortfolioStore.js View on Github external
this.prices = options.prices;
    this.ui = options.ui;

    // Rehydrate store from persisted data
    const data = localStorage.getItem(PORTFOLIO_KEY);
    if (data) {
      this.fromJSON(data);
    }

    // If user doens't have assets defined,
    // enter edit mode until they do
    if (!this.userDataReady) {
      this.isEditing = true;
    }

    if (EventEmitter.listenerCount(ipcRenderer, 'priceSetting') === 0) {
      ipcRenderer.on('priceSetting', (_event, setting) => {
        if (setting) {
          ipcRenderer.send(
            'priceUpdate',
            formatNumber(this.totalChange, 'USD', {
              directionSymbol: true,
              minPrecision: true,
            })
          );
        } else {
          ipcRenderer.send('priceUpdate', '');
        }
      });
    }

    autorun(() => {
github calvinmetcalf / rollup-plugin-node-builtins / src / es6 / stream.js View on Github external
function onerror(er) {
    cleanup();
    if (EE.listenerCount(this, 'error') === 0) {
      throw er; // Unhandled stream error in pipe.
    }
  }
github cacjs / cac / src / Cac.js View on Github external
handleError(err) {
    if (EventEmitter.listenerCount(this, 'error') === 0) {
      console.error(err.stack)
      process.exitCode = process.exitCode || 1
    } else {
      this.emit('error', err)
    }
  }
}
github nodekit-io / nodekit-darwin / src / nodekit / NKCore / lib-core / node / _tls_wrap.js View on Github external
function requestOCSP(self, hello, ctx, cb) {
  if (!hello.OCSPRequest || !self.server)
    return cb(null);

  if (!ctx)
    ctx = self.server._sharedCreds;
  if (ctx.context)
    ctx = ctx.context;

  if (listenerCount(self.server, 'OCSPRequest') === 0) {
    return cb(null);
  } else {
    self.server.emit('OCSPRequest',
                     ctx.getCertificate(),
                     ctx.getIssuer(),
                     onOCSP);
  }

  var once = false;
  function onOCSP(err, response) {
    if (once)
      return cb(new Error('TLS OCSP callback was called 2 times'));
    once = true;

    if (err)
      return cb(err);
github mamod / Comojs / js / node / stream / _stream_readable.js View on Github external
return function() {
    var state = src._readableState;
    debug('pipeOnDrain', state.awaitDrain);
    if (state.awaitDrain)
      state.awaitDrain--;
    if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) {
      state.flowing = true;
      flow(src);
    }
  };
}
github nodekit-io / nodekit-darwin / src / nodekit / NKCore / lib-core / node / _tls_wrap.js View on Github external
this._requestCert = requestCert;
  this._rejectUnauthorized = rejectUnauthorized;
  if (requestCert || rejectUnauthorized)
    this.ssl.setVerifyMode(requestCert, rejectUnauthorized);

  if (options.isServer) {
    this.ssl.onhandshakestart = onhandshakestart.bind(this);
    this.ssl.onhandshakedone = onhandshakedone.bind(this);
    this.ssl.onclienthello = onclienthello.bind(this);
    this.ssl.onnewsession = onnewsession.bind(this);
    this.ssl.lastHandshakeTime = 0;
    this.ssl.handshakes = 0;

    if (this.server &&
        (listenerCount(this.server, 'resumeSession') > 0 ||
         listenerCount(this.server, 'newSession') > 0 ||
         listenerCount(this.server, 'OCSPRequest') > 0)) {
      this.ssl.enableSessionCallbacks();
    }
  } else {
    this.ssl.onhandshakestart = function() {};
    this.ssl.onhandshakedone = this._finishInit.bind(this);
    this.ssl.onocspresponse = onocspresponse.bind(this);

    if (options.session)
      this.ssl.setSession(options.session);
  }

  this.ssl.onerror = function(err) {
    if (self._writableState.errorEmitted)
      return;
    self._writableState.errorEmitted = true;
github graalvm / graaljs / lib / tracing.js View on Github external
v8.on('newListener', function(name) {
  if (name === 'gc' && EventEmitter.listenerCount(this, name) === 0) {
    v8binding.startGarbageCollectionTracking(emitGC);
  }
});