How to use the events.EventEmitter.defaultMaxListeners 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 rochejul / sequelize-mocking / test / sequelize-mockingSpec.js View on Github external
describe('SequelizeMocking - ', function () {
    const expect = require('chai').expect;
    const sinon = require('sinon');

    const path = require('path');
    const EventEmitter = require('events').EventEmitter;
    const _ = require('lodash');

    const Sequelize = require('sequelize');
    const sequelizeFixtures = require('sequelize-fixtures');
    const SequelizeMocking = require('../lib/sequelize-mocking');

    const defaultMaxListeners = EventEmitter.defaultMaxListeners;

    it('shall exist', function () {
        expect(SequelizeMocking).to.exist;
        expect(_.isPlainObject(SequelizeMocking)).to.be.false;
    });

    let sinonSandbox;

    beforeEach(function () {
        sinonSandbox = sinon.sandbox.create();
        EventEmitter.defaultMaxListeners = 100; // Due to an error when we instanciate too many times fastly some dialects, like the MySql one
    });

    afterEach(function () {
        sinonSandbox.restore();
        EventEmitter.defaultMaxListeners = defaultMaxListeners;
github GetStream / Winds / api / src / workers / og.js View on Github external
import normalize from 'normalize-url';
import { EventEmitter } from 'events';

import db from '../utils/db';
import logger from '../utils/logger';
import { startSampling } from '../utils/watchdog';
import { removeQueueFlag } from '../utils/queue';
import RSS from '../models/rss'; // eslint-disable-line
import Podcast from '../models/podcast'; // eslint-disable-line
import Article from '../models/article';
import Episode from '../models/episode';
import { ParseOG, IsValidOGUrl } from '../parsers/og';
import { ProcessOgQueue, ShutDownOgQueue } from '../asyncTasks';

if (require.main === module) {
	EventEmitter.defaultMaxListeners = 128;

	logger.info('Starting the OG worker');
	ProcessOgQueue(35, ogProcessor);

	startSampling('winds.event_loop.og.delay');
}

export async function ogProcessor(job) {
	logger.info(`OG image scraping: ${job.data.url || job.data.urls}`);

	try {
		await handleOg(job);
	} catch (err) {
		const tags = { queue: 'og' };
		const extra = {
			JobURL: job.data.url || job.data.urls,
github wavebox / waveboxapp / src / scenes / mailboxes / src / WaveboxClient.js View on Github external
import { localHistoryStore, localHistoryActions } from 'stores/localHistory'
import { EventEmitter } from 'events'
import Debug from 'Debug'
import ResourceMonitorResponder from './ResourceMonitorResponder'
import TopLevelErrorBoundary from 'wbui/TopLevelErrorBoundary'
import {
  WB_MAILBOXES_WINDOW_JS_LOADED,
  WB_MAILBOXES_WINDOW_REQUEST_GRACEFUL_RELOAD,
  WB_MAILBOXES_WINDOW_ACCEPT_GRACEFUL_RELOAD
} from 'shared/ipcEvents'
import { ipcRenderer } from 'electron'
import CrashReporterWatcher from 'shared/CrashReporter/CrashReporterWatcher'
import os from 'os'

// We often exceed 10 listeners so increase this
EventEmitter.defaultMaxListeners = 50

// Context menu
document.addEventListener('contextmenu', (evt) => {
  if (evt.target.tagName === 'INPUT' || evt.target.tagName === 'TEXTAREA') {
    return
  }

  let node = evt.target
  while (node.tagName !== 'BODY') {
    if (node.getAttribute('data-contextmenu-target') === 'true') { return }
    node = node.parentElement
  }

  evt.preventDefault()
  evt.stopPropagation()
})
github GetStream / Winds / api / src / workers / rss.js View on Github external
import { ParseFeed, checkGuidStability, CreateFingerPrints } from '../parsers/feed';
import {
	ProcessRssQueue,
	ShutDownRssQueue,
	OgQueueAdd,
	StreamQueueAdd,
} from '../asyncTasks';
import { getStatsDClient, timeIt } from '../utils/statsd';
import { getStreamClient } from '../utils/stream';
import { startSampling } from '../utils/watchdog';
import { upsertManyPosts } from '../utils/upsert';
import { ensureEncoded } from '../utils/urls';
import { tryCreateQueueFlag, removeFromQueueFlagSet } from '../utils/queue';

if (require.main === module) {
	EventEmitter.defaultMaxListeners = 128;

	logger.info('Starting the RSS worker');
	ProcessRssQueue(35, rssProcessor);

	startSampling('winds.event_loop.rss.delay');
}

const streamTTL = 25200; // 7 hours
const duplicateKeyError = 11000;
const secondaryCheckDelay = 240000; // 4 minutes
const statsd = getStatsDClient();

function sleep(time) {
	return new Promise((resolve) => setTimeout(resolve, time));
}
github cliqz-oss / dat-webext / background / library.ts View on Github external
import { DatAPI } from './dat';
import { EventEmitter } from 'events';
import DatDb, { IDatInfo } from './db';

// suppress listener warnings
EventEmitter.defaultMaxListeners = 100;

const DEFAULT_SEED_TIME = 1e3 * 60 * 5; // 5 mins

export default class DatLibrary {

  api: DatAPI
  db: DatDb

  constructor(db: DatDb, node: DatAPI) {
    this.db = db;
    this.api = node;

    this.api.on('use', (dat) => {
      this.db.updateDat(dat, DEFAULT_SEED_TIME);
    });
  }
github rochejul / sequelize-mocking / test / sequelize-mockingSpec.js View on Github external
afterEach(function () {
        sinonSandbox.restore();
        EventEmitter.defaultMaxListeners = defaultMaxListeners;
    });
github signicode / scramjet / src / lib / multi-stream / remove.js View on Github external
MultiStream.prototype.remove =  function remove(stream) {

    const strIndex = this.streams.indexOf(stream);
    if (strIndex >= 0) {
        this.setMaxListeners(this.streams.length + EventEmitter.defaultMaxListeners);
        this.streams.splice(strIndex, 1);
        this.emit("remove", stream, strIndex);
    }

    if (!this.streams.length) {
        this.emit("empty");
    }

    return this;
};
github NickNaso / hertzy / lib / Frequency.js View on Github external
* MERCHANTABLITY OR NON-INFRINGEMENT.
 *
 * See the Apache Version 2.0 License for specific language governing
 * permissions and limitations under the License.
 *
 * Contributors - initial API implementation:
 * Nicola Del Gobbo 
 ***************************************************************************** */

'use strict'

const base = require('./base')
const objectValues = require('./object-values-polyfill')
const { EventEmitter } = require('events')

const DEFAULT_MAX_LISTENERS = EventEmitter.defaultMaxListeners

const _frequencyEmitters = new Map()

function getFrequencyStats(ee) {
    const evtNames = ee.eventNames()
    const stats = {}
    for (const evtName of evtNames) {
        stats[evtName] = ee.listenerCount(evtName)
    }
    return stats
}

function getFrequencyMaxListeners(frequencyStats) {
    const stats = objectValues(frequencyStats)
    return stats.length > 0 ? Math.max(...stats) : 0
}
github synyi / poplar / src / Annotator / Annotator.ts View on Github external
import {EventEmitter} from 'events';
import {Store} from "./Store/Store";
import {View} from "./View/View";
import {Dispatcher} from "./Dispatcher/Dispatcher";
import {Action} from "./Action/Action";
import {TextSelectionHandler} from "./View/EventHandler/TextSelectionHandler";
import {TwoLabelsClickedHandler} from "./View/EventHandler/TwoLabelsClickedHandler";

EventEmitter.defaultMaxListeners = 10000;

export class Annotator extends EventEmitter {
    store: Store;
    view: View;
    dispatcher: Dispatcher;
    textSelectionHandler: TextSelectionHandler;
    twoLabelsClickedHandler: TwoLabelsClickedHandler;

    constructor(data: string | object, private htmlElement: HTMLElement, public config?: object) {
        super();
        this.store = new Store();
        if (this.config) {
            const config = (this.config as any);
            if (config.maxLineWidth !== undefined) {
                this.store.config.maxLineWidth = config.maxLineWidth;
            }
github elderapo / typed-event-emitter / src / StrictEventEmitter.ts View on Github external
import { IEventEmitter, Event, Listener, Payload } from "./interfaces";
import { EventEmitter } from "events";

export class StrictEventEmitter implements IEventEmitter {
  private listenersMap: Map = new Map();
  private onceListeners: Listener[] = [];
  private maxListeners: number = EventEmitter.defaultMaxListeners;

  public addListener(event: Event, listener: Listener): this {
    return this.internalAddListener(event, listener);
  }

  public on(event: Event, listener: Listener): this {
    this.addListener(event, listener);
    return this;
  }

  public once(event: Event, listener: Listener): this {
    this.internalAddListener(event, listener, true, "back");
    return this;
  }

  public prependListener(event: Event, listener: Listener): this {