Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yohanmishkin/6825bee80e483befb56ba526e04fa446 to your computer and use it in GitHub Desktop.
Save yohanmishkin/6825bee80e483befb56ba526e04fa446 to your computer and use it in GitHub Desktop.
setTimeout() inside a foreach loop
$E.__container__.lookup('service:store').findAll('site').then((sites) => {
sites.forEach((x, index) => {
setTimeout(() => {
$E.__container__.lookup('service:gMap')
.geocode({address: x.get('location')})
.then((geocodes) => {
let lat = geocodes[0].geometry.location.lat();
let lng = geocodes[0].geometry.location.lng();
console.log(x.get('name'), lat, lng);
x.set('lat', lat);
x.set('lng', lng);
x.save();
})
.catch((err) => console.error(err));
}, 2000*(index+1));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment