index.js 846 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. function once(emitter, name, { signal } = {}) {
  4. return new Promise((resolve, reject) => {
  5. function cleanup() {
  6. signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', cleanup);
  7. emitter.removeListener(name, onEvent);
  8. emitter.removeListener('error', onError);
  9. }
  10. function onEvent(...args) {
  11. cleanup();
  12. resolve(args);
  13. }
  14. function onError(err) {
  15. cleanup();
  16. reject(err);
  17. }
  18. signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', cleanup);
  19. emitter.on(name, onEvent);
  20. emitter.on('error', onError);
  21. });
  22. }
  23. exports.default = once;
  24. //# sourceMappingURL=index.js.map