Last Updated: February 25, 2016
·
1.21K
· phaus

short test for background workers in NodeJS


#!/usr/bin/nodejs

 var path = require('path');

 #
 # this is just a short test for worker threads in node.
 #
 # touch update  => will trigger update functions
 # touch stop    => will stop Programm 
 #

 var timerID;
 function startTask(){
     timerID = setInterval(function () {
     console.log("step...");
     if (path.existsSync("stop")) {
         console.log("stopping");
         clearInterval(timerID);
     }
     if (path.existsSync("update")) {
         console.log("update...");       
             }
     },5000);
     console.log("starting:");
 }
 startTask();

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside