var socket = new Socket(); socket.bind(80); socket.listen(); while (true) { var client = socket.accept(); // blocking ... queryDB(); // blocking ... }
var socket = new Socket(); socket.bind(80); socket.listen(); while (true) { var client = socket.accept(); // blocking fork(); ... queryDB(); // blocking ... }
var socket = new Socket(); socket.bind(80); socket.listen(function (client) { // Non-blocking ... queryDB(function () { // Non-blocking ... }): });
while there are still events to process:
e = get the next event
if there is a callback associated with e:
call the callback
var fetchingData = $.get(url);
fetchingData.done(doneCallback);
fetchingData.fail(faildCallback);
var aDreamDeferred = new $.Deferred();
aDreamDeferred.done(function(subject) {
console.log('I had the wonderful dream about', subject);
});
aDreamDeferred.resolve('the JS event model');
try {
setTimeout(function () {
throw new Error('You can not catch me!!!');
}, 1000);
} catch (ex) {
console.log(ex);
}var start = new Date();
setTimeout(function(){
var end = new Date();
console.log('Time elapsed:', end - start, 'ms');
}, 500);
while (new Date() - start < 1000) {};
/
#