UNPKG

nodejslearnerfiles

Version:

Very Good Beginnings if you want to Learn Node.js

23 lines (19 loc) 646 B
var maxTime = 1000; // if input is even, double it // if input is odd, return error. // ( call takes random amount of time < 1 sec ) var evenDoubler = function(v, callback) { var waitTime = Math.floor(Math.random()*(maxTime+1)); if(v%2) { setTimeout(function (){ callback(new Error("Odd Input"),null, waitTime); }, waitTime); } else { setTimeout(function (){ callback(null, v*2, waitTime); }, waitTime); } }; // We are trying to get the evenDoubler available to other JavaScript files. or Other Parts of the application. module.exports.evenDoubler = evenDoubler; module.exports.foo = "bar";