Last active
May 30, 2019 20:59
-
-
Save jonahallibone/e2e285d66a98e8566e6739e13343041b to your computer and use it in GitHub Desktop.
for chris
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
| // 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