UNPKG

701 BJavaScriptView Raw
1/*!
2 * Copyright (c) 2012-2019 Digital Bazaar, Inc. All rights reserved.
3 */
4'use strict';
5
6const {EventEmitter} = require('async-node-events');
7
8const api = new EventEmitter();
9api.setMaxListeners(0);
10api.removeAllListeners('maxListenersPassed');
11module.exports = api;
12
13/**
14 * Schedules an event to be emitted on the next tick (via process.nextTick).
15 *
16 * @return a Promise that resolves to undefined once the event has been emitted
17 * to all listeners (or to `false` if it was canceled).
18 */
19api.emitLater = function(...args) {
20 // emit asynchronously
21 return new Promise((resolve, reject) => {
22 process.nextTick(() => {
23 api.emit(...args).then(resolve, reject);
24 });
25 });
26};