Created
April 18, 2017 21:26
-
-
Save yohanmishkin/6825bee80e483befb56ba526e04fa446 to your computer and use it in GitHub Desktop.
setTimeout() inside a foreach loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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