Slide 42
Slide 42 text
var messages = [
{ username: "snodgrass23", body: "How's the dog doing?" },
{ username: "dbecher", body: "Great, however my pillow is not so great after
she ripped it apart" },
{ username: "snodgrass23", body: "Have fun cleaning that up!" }
];
function getMessagesForUsername(username, callback) {
// some logic to iterate messages and return ones with requested username
callback(null, messages);
}
getMessagesForUsername("snodgrass23", function(err, messages1) {
getMessagesForUsername("dbecher", function(err, messages2) {
// do something with messages
});
});
this seems like it should be async and non-blocking because it’s using callbacks,
right?
in reality, the event loop is blocked the entire time that all of this is running. This
particular example would still run quickly, but in the real world,the message list would
be much longer and there may be more computations that have to run with each
result set which would also block.