Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6041979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:44:21+00:00 2026-05-23T06:44:21+00:00

Hi We are developing application in node.js , socket.io , and redis. we have

  • 0

Hi We are developing application in node.js , socket.io , and redis.

we have this procedure :

exports.processRequest = function (request,result) {
     var self = this;
     var timerknock;
     switch(request._command) {
    case 'some command': // user login with username 
            // some statement 
            timerknock=setTimeout(function() {
                //some  statemetn
            },20*1000);
        case 'other command ':
            // some statement    
            clearTimeout(timerknock);
      }
};

but when it cancel the timer it is not getting canceled when other command is executed , what should i do to cancel the timer ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:44:22+00:00Added an answer on May 23, 2026 at 6:44 am

    Looks like you don’t have break statements, which is going to cause problems (when you try and clear the timer it will make a new timer and clear it, but the old one will still run). Maybe that’s a typo.

    Your main problem is you’re storing the timer “reference” in a local variable. That needs to be either enclosed or global, otherwise when you execute the function to clear the variable, timerknock has lost its value and will try and clearTimeout(undefined) which is of course, useless. I suggest a simple closure:

    exports.processRequest = (function(){
       var timerknock;
       return function (request,result) {
          var self = this;
          switch(request._command) {
          case 'some command': // user login with username 
             // some statement 
             timerknock=setTimeout(function() {
                //some  statemetn
             },20*1000);
          case 'other command ':
             // some statement    
             clearTimeout(timerknock);
          }
       };
    })();
    

    Be aware that this too is a very simplistic approach, and if you set a timer before the current one has finished executing then you lose the reference to that timer. This might not be a problem for you, although you might try to implement this a little differently, with an object/array of timer references.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application, and have URLs in the format www.example.com/some_url/some_parameter/some_keyword . I
I am developing an application using MVC Preview 5. I have used typed views.
In the application I am developing I have polygons as show in the picture
When developing an application that sends out notification email messages, what are the best
I`m developing an application using Spring WebFlow 2, Facelets and JSF. One of my
I'm developing an application for Windows Mobile Devices using Visual Studio .NET 2008 whose
I am developing an application to install a large number of data files from
I am developing console application in .Net and I want to change a behavior
I'm developing an application targeting .NET Framework 2.0 using C# for which I need
I'm developing and application that runs as a Windows service. There are other components

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.