Skip to content

Commit

Permalink
NodeJS_4_Timers
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigobranas committed Apr 11, 2016
1 parent 9e274d4 commit ed90f68
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions NodeJS_4_Timers/clearInterval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var i = setInterval(function () {
console.log('I ' + new Date());
}, 1000);
setTimeout(function () {
clearInterval(i);
}, 5000);
7 changes: 7 additions & 0 deletions NodeJS_4_Timers/clearTimeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var a = setTimeout(function () {
console.log('A ' + new Date());
}, 3000);
var b = setTimeout(function () {
console.log('B ' + new Date());
}, 3000);
clearTimeout(a);
5 changes: 5 additions & 0 deletions NodeJS_4_Timers/setImmediate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
console.log('A ' + new Date());
setImmediate(function () {
console.log('I ' + new Date());
});
console.log('B ' + new Date());
4 changes: 4 additions & 0 deletions NodeJS_4_Timers/setImmediateTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.time('I');
setImmediate(function () {
console.timeEnd('I');
});
3 changes: 3 additions & 0 deletions NodeJS_4_Timers/setInterval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setInterval(function () {
console.log('I ' + new Date());
}, 1000);
4 changes: 4 additions & 0 deletions NodeJS_4_Timers/setTimeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.log('A ' + new Date());
setTimeout(function () {
console.log('B ' + new Date());
}, 3000);
10 changes: 10 additions & 0 deletions NodeJS_4_Timers/setTimeoutInterval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var interval = function (callback, time) {
setTimeout(function () {
callback();
interval(callback, time);
}, time);
};

interval(function () {
console.log('R ' + new Date());
}, 1000);
4 changes: 4 additions & 0 deletions NodeJS_4_Timers/setTimeoutReverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
setTimeout(function () {
console.log('B ' + new Date());
}, 3000);
console.log('A ' + new Date());
5 changes: 5 additions & 0 deletions NodeJS_4_Timers/setTimeoutZero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
console.log('A ' + new Date());
setTimeout(function () {
console.log('I ' + new Date());
}, 0);
console.log('B ' + new Date());
4 changes: 4 additions & 0 deletions NodeJS_4_Timers/setTimeoutZeroTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.time('T');
setTimeout(function () {
console.timeEnd('T');
}, 0);

0 comments on commit ed90f68

Please sign in to comment.