Lets say I have a function called getData()
const getData = (id) => {
doSomeStaff ...
}
Then I have another function as above
const callData = () => {
var idFromDatabases = ...
idFromDatabases.forEach(item => {
getData(item.id)
})
}
What I am trying to do is to delay each call of getData function. The easy way would be to setTimeout inside the callData function like above
const callData = () => {
var idFromDatabases = ...
idFromDatabases.forEach(item => {
setTimeout(getData(item.id), 3000)
})
}
But I want somehow the delay to happen into getData. Sow the basic idea is, from wherever getData is called, I want a time interval between calls. Any ideas?