codetogo.io icon indicating copy to clipboard operation
codetogo.io copied to clipboard

Use Case Suggestion: resolve all promises

Open Popesites opened this issue 4 years ago • 3 comments

Popesites avatar Dec 20 '19 07:12 Popesites

@Popesites What do you mean by resolve all promises ? or do you mean all promise should settle like this if the mdn link is as per the ask here, i can go ahead and implement it, or if that's not addressing the question here, I think we should still incorporate that as a separate use case ? What do you think @jadjoubran ?

Darth-koder007 avatar Dec 29 '19 08:12 Darth-koder007

@Darth-koder007 I meant resolving an array of promises asynchronously using await, something like this:

async () => {
  const result = await Promise.all(data.map(async obj => {
    const example = await Model.findOne({ someData: obj.someData });
    return example;
  }));
}

Popesites avatar Dec 31 '19 22:12 Popesites

Nice 👍 would be cool to have a short example that doesn't depend on an external library.. maybe using fetch?

jadjoubran avatar Jan 01 '20 13:01 jadjoubran