1 | /*!
|
2 | * Copyright (c) 2012-2019 Digital Bazaar, Inc. All rights reserved.
|
3 | */
|
4 | ;
|
5 |
|
6 | const {EventEmitter} = require('async-node-events');
|
7 |
|
8 | const api = new EventEmitter();
|
9 | api.setMaxListeners(0);
|
10 | api.removeAllListeners('maxListenersPassed');
|
11 | module.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 | */
|
19 | api.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 | };
|