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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:25:54+00:00 2026-06-17T17:25:54+00:00

I have a very quirky api that can only handle a single request at

  • 0

I have a very quirky api that can only handle a single request at a time.
Therefore, I need to ensure that every time a request is made, it goes into a queue, and that queue is executed one request at a time, until it is empty.

Normally, I just use jQuery’s built in queue, since the site is already using jQuery. However, I was not sure if I could somehow decorate the $http service, or wrap it in another service that returns one promise at a time, or something else.

  • 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-17T17:25:55+00:00Added an answer on June 17, 2026 at 5:25 pm

    Here is my solution for that: http://plnkr.co/edit/Tmjw0MCfSbBSgWRhFvcg

    The idea is: each run of service add request to queue and return promise. When request to $http is finished resolve/refuse returned promise and execute next task from queue if any.

    app.factory('srv', function($q,$http) {
    
      var queue=[];
      var execNext = function() {
        var task = queue[0];
        $http(task.c).then(function(data) {
          queue.shift();
          task.d.resolve(data);
          if (queue.length>0) execNext();
        }, function(err) {
          queue.shift();
          task.d.reject(err);
          if (queue.length>0) execNext();
        })
        ;
      }; 
      return function(config) {
        var d = $q.defer();
        queue.push({c:config,d:d});
        if (queue.length===1) execNext();            
        return d.promise;
      };
    });
    

    Looks quite simple 🙂

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

Sidebar

Related Questions

I have very big solution, and it compiling every time I'm tring to debug.
i have very serious problem if any tech expert can help...thank you in advance..
I have very very big html page/data. I need to fetch data under h1
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
I have very little to go on here. I can't reproduce this locally, but
I have very little experience using regular expressions and I need to parse an
I have a very strange issue regarding only IE8 + Windows Vista, the error
I have run into a quirk in MYSQL that is proving to be very
I have very simple query. I want to make sure that I don't have
I have very limited resources (RAM) on my server (Debian lenny) and I need

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.