Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
handle callbacks in order no matter which one finish first and handle them as a list.
CoffeeScript JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
.gitignore
.npmignore
.travis.yml
Cakefile
README.md
order.js
package.json

README.md

Order

Flow control to keep callbacks in order no matter which one finishs first and handle them as a list.

install

npm install order

usage

var Order = require('order');

list = new Order(function (idx) {
    // handle here ready elements
    idx.before;  // index of the previous element that is ready before idx.i
    idx.i;       // index of the element that got ready
    idx.after;   // index of the next element that is ready after idx.i
    this[idx.i]; // the ready element
});

list.push(function (done) {
    var element = {value:3}; // create new element
    setTimeout(function () { // fake async call
        element.value = 5;   // now set real value
        done();              // say, that this element is ready
    }, 23);
    return element;
});

When calling done the callback given to the constructor gets called.

api

It it basically the exact same api like javascripts Array has with the little exception, that it doesn't take direct values, but functions that return the value. Also it is not possible to specify an Order with a given size like new Array(23).

Build Status

Something went wrong with that request. Please try again.