Skip to content

Simulate the tournament #161

Answered by Drarig29
klemonade asked this question in Q&A
Mar 24, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hey! So you have 2 issues here.

First, be aware that functional array methods in JS — like map(), reduce(), forEach() — are not compatible with async. They won't await between each iteration as you might think.

So what you should do instead of using forEach() is to map() your array items to an array of promises, that can then be awaited with Promise.all():

await Promise.all(data.match.map(async (match) => {
  // ...
  await manager.update.match({ ... })
}))

And second, what you are doing here is running promises in concurrence (NB: Node.js doesn't do parallel).

But my storage implementations — brackets-json-db, brackets-memory-db... — do not support concurrent operations.
Since you are up…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Drarig29
Comment options

@klemonade
Comment options

Answer selected by klemonade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants