diff --git a/NodeJS_4_Timers/clearInterval.js b/NodeJS_4_Timers/clearInterval.js new file mode 100644 index 00000000..a6913a41 --- /dev/null +++ b/NodeJS_4_Timers/clearInterval.js @@ -0,0 +1,6 @@ +var i = setInterval(function () { + console.log('I ' + new Date()); +}, 1000); +setTimeout(function () { + clearInterval(i); +}, 5000); \ No newline at end of file diff --git a/NodeJS_4_Timers/clearTimeout.js b/NodeJS_4_Timers/clearTimeout.js new file mode 100644 index 00000000..e7c1025a --- /dev/null +++ b/NodeJS_4_Timers/clearTimeout.js @@ -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); \ No newline at end of file diff --git a/NodeJS_4_Timers/setImmediate.js b/NodeJS_4_Timers/setImmediate.js new file mode 100644 index 00000000..059e1d6b --- /dev/null +++ b/NodeJS_4_Timers/setImmediate.js @@ -0,0 +1,5 @@ +console.log('A ' + new Date()); +setImmediate(function () { + console.log('I ' + new Date()); +}); +console.log('B ' + new Date()); \ No newline at end of file diff --git a/NodeJS_4_Timers/setImmediateTime.js b/NodeJS_4_Timers/setImmediateTime.js new file mode 100644 index 00000000..fa6262e2 --- /dev/null +++ b/NodeJS_4_Timers/setImmediateTime.js @@ -0,0 +1,4 @@ +console.time('I'); +setImmediate(function () { + console.timeEnd('I'); +}); \ No newline at end of file diff --git a/NodeJS_4_Timers/setInterval.js b/NodeJS_4_Timers/setInterval.js new file mode 100644 index 00000000..cb3994c0 --- /dev/null +++ b/NodeJS_4_Timers/setInterval.js @@ -0,0 +1,3 @@ +setInterval(function () { + console.log('I ' + new Date()); +}, 1000); \ No newline at end of file diff --git a/NodeJS_4_Timers/setTimeout.js b/NodeJS_4_Timers/setTimeout.js new file mode 100644 index 00000000..2cf81977 --- /dev/null +++ b/NodeJS_4_Timers/setTimeout.js @@ -0,0 +1,4 @@ +console.log('A ' + new Date()); +setTimeout(function () { + console.log('B ' + new Date()); +}, 3000); \ No newline at end of file diff --git a/NodeJS_4_Timers/setTimeoutInterval.js b/NodeJS_4_Timers/setTimeoutInterval.js new file mode 100644 index 00000000..fc92f990 --- /dev/null +++ b/NodeJS_4_Timers/setTimeoutInterval.js @@ -0,0 +1,10 @@ +var interval = function (callback, time) { + setTimeout(function () { + callback(); + interval(callback, time); + }, time); +}; + +interval(function () { + console.log('R ' + new Date()); +}, 1000); \ No newline at end of file diff --git a/NodeJS_4_Timers/setTimeoutReverse.js b/NodeJS_4_Timers/setTimeoutReverse.js new file mode 100644 index 00000000..2c96017d --- /dev/null +++ b/NodeJS_4_Timers/setTimeoutReverse.js @@ -0,0 +1,4 @@ +setTimeout(function () { + console.log('B ' + new Date()); +}, 3000); +console.log('A ' + new Date()); \ No newline at end of file diff --git a/NodeJS_4_Timers/setTimeoutZero.js b/NodeJS_4_Timers/setTimeoutZero.js new file mode 100644 index 00000000..469ca8d7 --- /dev/null +++ b/NodeJS_4_Timers/setTimeoutZero.js @@ -0,0 +1,5 @@ +console.log('A ' + new Date()); +setTimeout(function () { + console.log('I ' + new Date()); +}, 0); +console.log('B ' + new Date()); \ No newline at end of file diff --git a/NodeJS_4_Timers/setTimeoutZeroTime.js b/NodeJS_4_Timers/setTimeoutZeroTime.js new file mode 100644 index 00000000..21ee5465 --- /dev/null +++ b/NodeJS_4_Timers/setTimeoutZeroTime.js @@ -0,0 +1,4 @@ +console.time('T'); +setTimeout(function () { + console.timeEnd('T'); +}, 0); \ No newline at end of file