4. requestHandlers.js - sleep function

Created Saturday 30 November 2013

// The sleep function helps to demonstrate the problem of time-consuming computation in our handle.
// Open 2 browser windows simultaneousely, in the first open /start and immediately after that in the second — /update.
function start () {

console.log ("Request handler 'start' was called");
function sleep (milliSeconds) {
var startTime = new Date ().getTime ();
while (new Date ().getTime () < startTime + milliSeconds);
}
sleep (10000);
return "Hello Start";
}

function upload () {

console.log ("Request handler 'upload' was called");
return "Hello Upload";
}

exports.start = start;
exports.upload = upload;



Backlinks: