- Create an RDS instance
- SSH to gerrit and cd to /opt/gerrit/site
- Stop gerrit and open the gerrit prompt
bin/gerrit.sh stop
java -jar bin/gerrit.war 'gsql' -d .
- Copy in the below
bin/gerrit.sh stop
java -jar bin/gerrit.war 'gsql' -d .
getUserData(function doStuff(e, a) { | |
getMoreUserData(function doMoreStuff(e, b) { | |
getEvenMoreUserData(function doEvenMoreStuff(e, c) { | |
getYetMoreUserData(function doYetMoreStuff(e, c) { | |
console.log('Welcome to callback hell!'); | |
}); | |
}); | |
}); | |
}) |
// Suppose that we have a method fetchJson() that does GET requests and has an interface that looks | |
// like this, where callback is expected to take error as its first argument and the parsed response | |
// data as its second. | |
function fetchJson(url, callback) { ... } | |
fetchJson('/api/user/self', function(e, user) { | |
fetchJson('/api/interests?userId=' + user.id, function(e, interests) { | |
var recommendations = []; | |
interests.forEach(function () { | |
fetchJson('/api/recommendations?topic=' + interest, function(e, recommendation) { | |
recommendations.push(recommendation); |
fetchJson('/api/user/self') | |
.then(function (user) { | |
return fetchJson('/api/user/interests?userId=' + self.id); | |
}) | |
.then(function (interests) { | |
return Promise.all[interests.map(i => fetchJson('/api/recommendations?topic=' + i))]; | |
}) | |
.then(function (recommendations) { | |
render(user, interests, recommendations); | |
}); |
fetchJson('/api/user/self') | |
.then(function (user) { | |
return fetchJson('/api/user/interests?userId=' + self.id) | |
.then(interests => { | |
user: user, | |
interests: interests | |
}); | |
}) | |
.then(function (blob) { | |
return Promise.all[blob.interests.map(i => fetchJson('/api/recommendations?topic=' + i))] |
// We declare these variables we want to save ahead of time. | |
var user, recommendations; | |
fetchJson('/api/user/self') | |
.then(function (fetchedUser) { | |
user = fetchedUser; | |
return fetchJson('/api/user/interests?userId=' + self.id); | |
}) | |
.then(function (fetchedInterests) { | |
interests = fetchedInterests; | |
return Promise.all(interests.map(i => fetchJson('/api/recommendations?topic=' + i))); |
co(function* () { | |
var user = yield fetchJson('/api/user/self'); | |
var interests = yield fetchJson('/api/user/interests?userId=' + self.id); | |
var recommendations = yield Promise.all( | |
interests.map(i => fetchJson('/api/recommendations?topic=' + i))); | |
render(user, interests, recommendations); | |
}); |
function* counts(start) { | |
yield start + 1; | |
yield start + 2; | |
yield start + 3; | |
return start + 4; | |
} | |
const counter = counts(0); | |
console.log(counter.next()); // {value: 1, done: false} | |
console.log(counter.next()); // {value: 2, done: false} | |
console.log(counter.next()); // {value: 3, done: false} |
function* printer() { | |
console.log("We are starting!"); | |
console.log(yield); | |
console.log(yield); | |
console.log(yield); | |
console.log("We are done!"); | |
} | |
const counter = printer(); | |
counter.next(1); // We are starting! | |
counter.next(2); // 2 |
function makeCounter() { | |
var count = 1; | |
return function () { | |
return count++; | |
} | |
} | |
var counter = makeCounter(); | |
console.log(counter()); // 1 | |
console.log(counter()); // 2 | |
console.log(counter()); // 3 |