Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do sequential asynchronous ajax requests with given number of streams
    primarykey
    data
    text
    <p>I need to make sequential asynchronous ajax requests with limited streams. As of now I am allowed to occupy only one stream on web server so I can only do one ajax request at time.</p> <p>I have following function which helps me when I am allowed to use only one stream at a time.</p> <pre><code>function initiateChain() { var i = 0; var tasks = arguments; var callback = function () { i += 1; if (i != tasks.length) { tasks[i](callback); //block should call callback when done otherwise loop stops } } if (tasks.length != 0) { tasks[0](callback); //initiate first one } } </code></pre> <p>Say if I have three ajax helper functions</p> <pre><code> function getGadgets(callback) { //ajax call callback(); // I call this in complete callback of $.ajax } function getBooks(callback) { //ajax call callback(); // I call this in complete callback of $.ajax } function getDeals(callback) { //ajax call callback(); // I call this in complete callback of $.ajax } </code></pre> <p>following call ensures that no more than 1 ajax request is made from this client</p> <pre><code>initiateChain(getGadgets, getBooks, getDeals); </code></pre> <p>Now I need to enhance initiateChain to support arbitrary number of streams. Say I am allowed to use 2 or n number of streams I would like to know ideas to do so without changing ajax helper functions getGadgets, getDeals, getDeals.</p> <p>In short, I have a set of functions, N, in this case getGadgets, getDeals and getDeals(|N|=3) that each need a connection to the web server. Currently, I can only execute one request at a time, so initiateChain function calls the three methods in sequence. If I had access to M connections, I would like to execute |N| functions in parallel (up to a maximum of M).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload