1const promises = [];
2
3for (let i=30; i >= 1; i--) {
4 const date = new Date();
5 const previousDay = Math.floor(date.setDate(date.getDate() - i) / 1000);
6 const url = `/api/darksky?latitude=${current.latitude}&longitude=${current.longitude},${previousDay}`;
7 promises.push(darkSky(url, this.onTimeRequestSuccess, this.onError));
8}
9
10Promise.all(promises).then(arrOfResults => {
11 // setState here
12});
13
1public async Task RunAsync()
2{
3 var tasks = new List<Task>();
4
5 foreach (var x in new[] { 1, 2, 3 })
6 {
7 var task = DoSomethingAsync(x);
8 tasks.Add(task);
9 }
10
11 await Task.WhenAll();
12}
13