Skip to content

Instantly share code, notes, and snippets.

@jaredlockhart
Created July 3, 2019 16:55
Show Gist options
  • Save jaredlockhart/763e24ee2c699f7626dd590fd78cc2a7 to your computer and use it in GitHub Desktop.
Save jaredlockhart/763e24ee2c699f7626dd590fd78cc2a7 to your computer and use it in GitHub Desktop.
function getPeople(callback) {
$.get("people", callback);
}
function getPerson(id, callback) {
$.get("person/{id}", callback);
}
function storePerson(data, callback) {
db.call("INSERT INTO PEOPLE VALUES {data}", callback);
}
getPeople(function(people) {
for(person in people) {
getPerson(person["id"], function (personData) {
storePerson(personData, function (dbOK) {
console.log("person stored");
}
}
}
})
function getPeople() {
return fetch("people");
}
function getPerson(id) {
return fetch("person/{id}");
}
function storePerson(data) {
return db.call("INSERT INTO PEOPLE VALUES {data}");
}
getPeople().then(people => {
for (person in people) {
getPerson(person["id"]).then(data => {
storePerson(data).then(dbOK => {
console.log("person stored");
});
})
}
})
let people = await getPeople();
for (person in people) {
let data = await getPerson(person["id"]);
let dbOK = await storePerson(data);
console.log("person stored");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment