WHERE name=?'; var user = query(sql, name); // <- blocking if (!user) throw new Error('no user!'); return user; } function getUser(name, callback) { var sql = 'SELECT * FROM users WHERE name=?'; query(sql, name, function (error, user) { if (error) { callback(error); } else if (!user) { callback(new Error('no user!')); } else { callback(null, user); } }); }
WHERE name=?'; var user = query(sql, name); // <- blocking if (!user) throw new Error('no user!'); return user; } function getUser(name, callback) { var sql = 'SELECT * FROM users WHERE name=?'; query(sql, name, function (error, user) { if (error) { callback(error); } else if (!user) { callback(new Error('no user!')); } else { callback(null, user); } }); }
WHERE name=?'; var user = query(sql, name); // <- blocking if (!user) throw new Error('no user!'); return user; } function getUser(name, callback) { var sql = 'SELECT * FROM users WHERE name=?'; query(sql, name, function (error, user) { if (error) { callback(error); } else if (!user) { callback(new Error('no user!')); } else { callback(null, user); } }); }
while (true) { yield i; // <- awesome var t = i; i = j; j += t; } } var generator = fibonacci(); for (var i = 0; i < 12; i++) { print(generator.next()); }
using callbacks getUser('mjackson', function (user) { getNewTweets(user, function (tweets) { updateTimeline(tweets); }); }); // using promises getUser('mjackson') .then(getNewTweets) .then(updateTimeline);