It looks like you don't have break statements that will cause problems (when you try to clear the timer, it will make a new timer and clear it, but the old one will work). Perhaps this is a typo.
The main problem is that you save the timer βlinkβ in a local variable. It must be either closed or global, otherwise, when you execute the function to clear the variable, timerknock lost its value and will try clearTimeout(undefined) , which, of course, is useless. I suggest a simple close:
exports.processRequest = (function(){ var timerknock; return function (request,result) { var self = this; switch(request._command) { case 'some command':
Remember that this is also a very simplified approach, and if you set a timer before the current one finishes executing, you will lose the link to this timer. This may not be a problem for you, although you can try to implement it a little differently with an object / array of timer references.
source share