Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 11: use of counter is not tested #145

Open
ghost opened this issue Jul 14, 2018 · 4 comments
Open

Exercise 11: use of counter is not tested #145

ghost opened this issue Jul 14, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Jul 14, 2018

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
Copy link

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

@ghost
Copy link
Author

ghost commented Sep 13, 2018

@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
Copy link

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

@ghost
Copy link
Author

ghost commented Sep 13, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant