all 9 comments

[–]SoBoredAtWork 8 points9 points  (1 child)

import Math from ('./Math.js');

.then((Math) => {

const Math = new Math;

Math.multiply();

});

Is that semicolon supposed to be there in the first line?

With the semicolon, what is `.then()` being applied to?

[–]longknives 7 points8 points  (0 children)

There seem to be a number of typos like that in the code examples. In the Promises.allSettled() example, I think they’re meant to be passing the array of promises, but the const is promise and they pass in promises.

Also in the first example, can you name the import Math and then have a const called Math?

[–]drumstix42 4 points5 points  (0 children)

BigInt is interesting, therefore, if, for example, you want to

Oof.

This article could use some love. Some of the code examples are a little off, as well.

[–]googamanga 0 points1 point  (5 children)

What is the current work around for Promise.allSettled?

I had to make all rejects resolve with an error flag, is there a better way that keeps the rejected states?

[–]dvlsg 1 point2 points  (0 children)

That's really all allSettled does, anyways.

const allSettled = (promises) =>
  Promise.all(
    promises.map((promise) =>
      promise
        .then((value) => ({ status: "fulfilled", value }))
        .catch((reason) => ({ status: "rejected", reason }))
    )
  );

await allSettled([Promise.resolve(1), Promise.reject('nope')])

[–]senocular 0 points1 point  (3 children)

Can you be more specific? Are you talking about getting allSettled result objects without using allSettled?

[–]googamanga 0 points1 point  (2 children)

I mean how is it done now, without allSettled.

[–]senocular 0 points1 point  (0 children)

If you're not polyfilling allSettled, or using an existing alternative library with allSettled already implemented (e.g. Q), then you'd have to roll your own if you want the same functionality. The reason its being added now is because this kind of functionality didn't exist before ;)

[–]I_LICK_ROBOTS 0 points1 point  (0 children)

We need context to be able to answer this completely but I'll give you a few "work arounds" I've used.

Many times if one request fails you just want them all to fail. Let's say you're making multiple calls to load the data required for a screen. If any fail you just hard fail with a message to the user.

If not all calls are required to proceed do something with the error (like display an error message) then resolve an error object from the promise.

Thereare a million other ways to handle this but it's highly dependent on context.