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 7844473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:53:04+00:00 2026-06-02T16:53:04+00:00

I have this code: var getStuff = function(resources, callback, progressCallback){ var deferreds = [];

  • 0

I have this code:

var getStuff = function(resources, callback, progressCallback){
  var deferreds = [];
  for(var idx = 0; idx < resources.length; idx++){
     ...
     deferreds.push(<some action>);
  }

  jQuery.when.apply(null, deferreds).then(function(){
    callback && callback();
  });
});

So, this will trigger my callback if I call it with:

getStuff([
  'foo',
  'bar'
], function(){
  console.log("Finished doing stuff!");
});

Question is: How can I make a progressCallback?

Something like:

getStuff([
  'foo',
  'bar'
], function(){
  console.log("Finished doing stuff!");
}, function(obj){
  console.log("Doing stuff with obj: " + obj);
});

Regards!

  • 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-02T16:53:06+00:00Added an answer on June 2, 2026 at 4:53 pm

    You could try this approach (I didn’t tried)

    var getStuff = function(resources, callback, progressCallback) {
    
        var deferreds = [];
            len       = resources.length; // need a variable for later iteration
    
        for(var idx = 0; idx < len; idx++){
           deferreds.push(<some action>);
        }
    
    
        deferreds.reverse();  // So the order of deferred lookup is preserved
    
        /* we create a named self-executed function, so we can call it when 
           a deferred is done and len variable is decremented */
    
        (function iterateWhen() {
           if (len--) {
             /* call progress callback */
             progressCallback(deferreds[len]); 
             jQuery.when(deferreds[len]).then(function() {
                iterateWhen();
             });
           }
           else {     
              callback && callback();
           }
        }());
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: var ar = [10,7,8,3,4,7,6]; function isin(n,a){ for (var i=0;i<a.length;i++){ if
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
I have this code: for(var i in this.units) { if(this.units[i].x==att.x && this.units[i].y==att.y){} //... some
I have this code here: var Person = (function() { var name; var PersonConstructor
I have this code: var originalBorder = container.css("border"); container.hover(function(event) { event.stopPropagation(); $(this).css("border", "1px solid
I have this code: var addNew = $('#divListBox').find(':checked') .map(function() { return $(this).val(); }).get(); I
I have this code : var infoWindowOptions = { content: content, ... some other
I have this code var stats = { GetMetaData : function() { var url
All, I have this code: var speed= 1000, num = 1, timer; (function rotate()
I'm having some difficulties with passing functions around. I have this code: var options

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.