DEV Community

Discussion on: Simplify your Node code with Continuation Local Storage variables

Collapse
 
miketalbot profile image
Mike Talbot ⭐

I was asked this by a colleague: what about setInterval(). The answer is "yes" it works as a continuation:

      app.get('/path', cls.$init(function handler(req,res) {
             cls.audit = async function(message, content) {
                  await mysql.insert(...);
             }
             ...
             cls.timerInterval = setInterval(checkSomething, 60000);
      }))

     function checkSomething() { 
          cls.audit("checked", {time: Date.now()})
          if(somethingHappenend) clearInterval(cls.timerInterval);
     }