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

  • SEARCH
  • Home
  • 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 8206453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:40:33+00:00 2026-06-07T08:40:33+00:00

I have been experimenting a lot with setInterval and clearInterval recently, for creating my

  • 0

I have been experimenting a lot with setInterval and clearInterval recently, for creating my own custom effects and one of the things that I have been working on is an efficient way to clear an interval whilst staying out of the global scope. I am trying to improve readability and explore possible performance boosts by using .promise() to call clearInterval() (the below is an example of what I’m trying to do):

//caller is a collection of elements
function performEffect(caller) {
   var interval = setInterval(function() { caller.next(); }, 500);
   caller.promise().done(function() { interval = clearInterval(interval); });
}

Up until recently, I had been setting and clearing the interval using an embedded function (example):

function performEffect(caller) {
   var interval;
   var count = 0;
   var len = caller.length;

   if (count >= len) {
       interval = clearInterval(interval);
   }

   var tmr = function () {
       interval = setInterval(function () { effectFunciton(count++); }, 100);
   }
}

P.S. I’m sorry for not posting the original – my versioning system was corrupted. Also, I know that this example is kind of silly, since I could easily use a for-loop or a .each(), but it’s just an example – I do have instances where I do not want to use a loop.

This is my first post, so I apologize ahead of time if I do something different from the accepted practice. Please let me know if there is anything I can do to improve my posts in the future – I’m always open to constructive criticism 🙂

Thanks!

  • 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-06-07T08:40:36+00:00Added an answer on June 7, 2026 at 8:40 am

    You’ll want to use deferreds for this. I wrote an example on jsfiddle a little while ago that may give you some insight.

    http://jsfiddle.net/landau/M3Lj4/

    From your code, it looks like you are misunderstanding deferreds in general or there isn’t enough code here to tell what you are doing. Promises hides resolving and rejecting functionality

    Basically,

    var deferred = $.Deferred();
    var promise = deferred.promise();
    
    // This will only run once
    var timer = setInterval( function () {
        deferred.resolve();
    }, 1000);
    
    promise.done(function () {
        clearInterval( timer );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been experimenting a lot with some glassy images, such as the one
I have been experimenting with a lot of web development apps like Drupal, Moodle,
I have been experimenting with writing applications that use a local SQL Database to
I'm working on building a tree structure in MySQL and have been experimenting with
I have been experimenting recently with Silverlight, RIA Services, and Entity Framework using .NET
I have been experimenting with LOAD DATA INFILE and there are a couple things
I have been experimenting with the devkitARM toolchain for NDS homebrew recently. Something I
I am a JS programmer and I have been experimenting with jQuery a lot
I have been experimenting a lot lately with Windows 8, writing C# XAML Metro
I have been experimenting with Firefox's Audio API to detecting silence in audio. (The

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.