stevekane / promise-it-wont-hurt

A Workshopper module that teaches you to use promises in javascript
737 stars 219 forks source link

Exercise 11: use of counter is not tested #145

Open ghost opened 6 years ago

ghost commented 6 years ago

Here's a solution for the problem 11 that doesn't use a counter and still passes:

function all (p1, p2) {
  let vals = [];
  let internalPromise = new Promise((resolve, reject) => {
    resolve(
      p1
      .then(r1 => vals.push(r1))
      .then(() => p2)
      .then(r2 => vals.push(r2))
      .then(() => vals)
    );
  });
  return internalPromise;
}

all(getPromise1(), getPromise2()).then(console.log);

I'm glad I passed (took me a long time…), but either the wording of the task should be changed to allow such a thing explicitly, or I should've failed, since I didn't even use a counter.

noalevit18 commented 6 years ago

Your solution is not async, you perform p2 after you finish performing p1

ghost commented 6 years ago

@noalevit Can you explain a little bit more what you mean by not async? I just wait for p1 to finish and then wait for p2 to finish and only then I resolve the „parent“ promise. Isn’t that what’s supposed to be happening?

noalevit18 commented 6 years ago

No, p1 and p2 should happen in parallel, you shoundn't wait for p1 to finish in order to start p2

ghost commented 6 years ago

Ah, I see what you're saying now. I guess my initial point still stands, though: I pass the challenge in this way, even though I shouldn't. That should change.