nika-begiashvili / libarchivejs

Archive library for browsers
MIT License
285 stars 35 forks source link

Promise.withResolvers #65

Closed sp90 closed 8 months ago

sp90 commented 8 months ago

When trying to create an archive in the browser chrome v120 i get the

ERROR TypeError: Promise.withResolvers is not a function

this is probably due to it not being supported yet in most browsers suggesting an alternative implementation like

let resolve, reject;

const promise = new Promise((res, rej) => {
  resolve = res;
  reject = rej;
});

I know it doesn't look as nice in the code but its gonna have a much better browser support

nika-begiashvili commented 8 months ago

Use this polyfill for now, I'll include it in next version

// Polyfill for Promise.withResolvers on nodejs
(Promise as any).withResolvers ||
  ((Promise as any).withResolvers = function withResolvers() {
    var a,
      b,
      c = new this(function (resolve: Function, reject: Function) {
        a = resolve;
        b = reject;
      });
    return { resolve: a, reject: b, promise: c };
  });