Skip to content
Advertisement

Grouping asynchronous functions to run

I have a code that outputs numbers from 1 to 10:

JavaScript

Output:

1 2 3 4 5 6 7 8 9 10

It is noticeable that in the example above, 10 functions are simultaneously launched at once. How can I fix the code so that the number of concurrent launched functions main() is equal to count_group? That is, immediately the output should be 123, then 456, then 789 and at the end 10.

Advertisement

Answer

Split your tasks into run groups and gather() each group one by one.

Example:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement