I need to execute a chain of promises with a timer for external requests. As someone suggested in the similar thread I used async/await and rewrite it a bit:
class myClass{
constructor(symbols){
this.downloadCsv(symbols)
}
// async/await method executing requests with timer
static async downloadCsv(symbols){
const result = [];
symbols.forEach(symbol => {
await timer(1000)
result.push(await this.downloadOneCsv(symbol['symbol']) )
}
return result
}
downloadOneCsv(symbol){
//request goes here
}
}
While executing a code above I keep receving an error message suggesting that async/await is not valid:
await timer(1000) ^^^^^
SyntaxError: await is only valid in async function
How can I fix it?