Answers for "react async loop"

0

react async loop

const promises = [];

for (let i=30; i >= 1; i--) {
    const date = new Date();
    const previousDay = Math.floor(date.setDate(date.getDate() - i) / 1000);
    const url = `/api/darksky?latitude=${current.latitude}&longitude=${current.longitude},${previousDay}`;
    promises.push(darkSky(url, this.onTimeRequestSuccess, this.onError));
}

Promise.all(promises).then(arrOfResults => {
  // setState here
});
Posted by: Guest on August-04-2021
0

C# foreach loop async but wait at end

public async Task RunAsync()
{
    var tasks = new List<Task>();
 
    foreach (var x in new[] { 1, 2, 3 })
    {
        var task = DoSomethingAsync(x);
        tasks.Add(task);
    }
 
    await Task.WhenAll();
}
Posted by: Guest on April-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language