Skip to content

Commit

Permalink
next
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasile committed May 23, 2017
1 parent a47cb27 commit 38045d5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions asyncExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

var evenDouble = function(v, callback){
var start = new Date();
setTimeout(function(){
var end = new Date();
var time = end.getTime() - start.getTime();

if (v % 2 == 0){
callback.call(null, 1, v*2, time);
}else{
callback.call(null, 0, -1, time);
}
},generateNumber(1,10) * 100);
}

function generateNumber(start,end){
return Math.floor(Math.random() * end) + start ;
}

var handler = function(err,result,time){
if (err){
console.log("ERR");
}else{
console.log("result: " + result + " in " + time + "ms");
};
};

for(let i = 0; i < 10; i++) {
evenDouble(i,handler);
}

0 comments on commit 38045d5

Please sign in to comment.