Skip to content

Instantly share code, notes, and snippets.

@jonahallibone
Last active May 30, 2019 20:59
Show Gist options
  • Select an option

  • Save jonahallibone/e2e285d66a98e8566e6739e13343041b to your computer and use it in GitHub Desktop.

Select an option

Save jonahallibone/e2e285d66a98e8566e6739e13343041b to your computer and use it in GitHub Desktop.
for chris
// Psuedo Code
const stores = [...]
let storesNotInFirebase = []
let timeoutID = TimeOut
stores.forEach(store => {
getFromFirebase(store).then(() =>
if(not_in_firebase) addToNotInFirebaseList(store)
)
});
function addToNotInFirebaseList() {
storesNotInFireBase.push(store);
if(timeoutID === null) {
timeoutID = setTimeout(() => getFromPlacesApi(), 100);
}
}
function getFromPlacesApi(store) {
storesNotInFirebase.forEach(store => {
const res = await fetchFromPlacesAPI(store) // this is for you to write
res.then( ... ) // this is for you
storesNotInFirebase = storesNotInFirebase.shift(); //remove from beginning
if(storesNotInFirebase.length) {
timeoutID = setTimeout(() => getFromPlacesApi(), 100); //keep going if there's any left
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment