bare-events 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +14 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -270,32 +270,35 @@ exports.once = function once (emitter, name, opts = {}) {
|
|
|
270
270
|
signal
|
|
271
271
|
} = opts
|
|
272
272
|
|
|
273
|
-
if (signal && signal.aborted) {
|
|
274
|
-
throw errors.OPERATION_ABORTED(signal.reason)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
273
|
return new Promise((resolve, reject) => {
|
|
274
|
+
if (signal && signal.aborted) {
|
|
275
|
+
return reject(errors.OPERATION_ABORTED(signal.reason))
|
|
276
|
+
}
|
|
277
|
+
|
|
278
278
|
if (signal) signal.addEventListener('abort', onabort)
|
|
279
279
|
|
|
280
|
+
if (name !== 'error') emitter.on('error', onerror)
|
|
281
|
+
|
|
280
282
|
emitter.once(name, (...args) => {
|
|
281
283
|
if (signal) signal.removeEventListener('abort', onabort)
|
|
282
284
|
|
|
285
|
+
if (name !== 'error') emitter.off('error', onerror)
|
|
286
|
+
|
|
283
287
|
resolve(args)
|
|
284
288
|
})
|
|
285
289
|
|
|
290
|
+
function onerror (err) {
|
|
291
|
+
reject(err)
|
|
292
|
+
}
|
|
293
|
+
|
|
286
294
|
function onabort () {
|
|
287
295
|
reject(errors.OPERATION_ABORTED(signal.reason))
|
|
288
296
|
}
|
|
289
297
|
})
|
|
290
298
|
}
|
|
291
299
|
|
|
292
|
-
exports.forward = function forward (from, to,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (typeof opts === 'string') {
|
|
296
|
-
names.push(opts)
|
|
297
|
-
opts = {}
|
|
298
|
-
}
|
|
300
|
+
exports.forward = function forward (from, to, names, opts = {}) {
|
|
301
|
+
if (typeof names === 'string') names = [names]
|
|
299
302
|
|
|
300
303
|
const {
|
|
301
304
|
emit = to.emit.bind(to)
|