UNPKG

aria2

Version:

Library and for aria2, "The next generation download utility."

21 lines (19 loc) 472 B
"use strict"; module.exports = function promiseEvent(target, event) { return new Promise((resolve, reject) => { function cleanup() { target.removeListener(event, onEvent); target.removeListener("error", onError); } function onEvent(data) { resolve(data); cleanup(); } function onError(err) { reject(err); cleanup(); } target.addListener(event, onEvent); target.addListener("error", onError); }); };