-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunInLoopTest1Node.js
More file actions
30 lines (24 loc) · 885 Bytes
/
runInLoopTest1Node.js
File metadata and controls
30 lines (24 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var runInLoop = require("./runInLoop").runInLoop;
//async function that we want to run n times in a pausable loop
//the last parameter is a callback to be run after each iteration
var asyncPrint = function(txt1, txt2, onDone){
console.log("print start: " + txt1 + " - " + txt2);
setTimeout(function(){
console.log("print end: " + txt1 + " - " + txt2);
var result = txt1 + " " + txt2;
onDone(result);
}, 400);
};
var asyncPrintOnDone = function(result){
console.log("asyncPrintOnDone: " + result);
};
console.log("single execution:");
asyncPrint("hi there", "guys", asyncPrintOnDone);
console.log("looped execution 1:");
runInLoop(asyncPrint, 5, "hi there", "guys", asyncPrintOnDone, test2);
function test2(){
console.log("looped execution 2:");
runInLoop(asyncPrint, 3, "hi there", "guys", asyncPrintOnDone, function(){
console.log("the asyncLoop is done");
});
}