0.0.3 • Published 9 years ago

habitants-async-queue v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

Async Queue Build Status

Manages methods that need to be run in sequence and at a particular rate. It will never return perfect values, because computation takes time, but it should be pretty close.

Example

var asyncQueue = require('habitants-async-queue');

var newUnit = new Unit('adsf');
var startTime = new Date();

newUnit.move(startTime);
newUnit.build(startTime);

function Unit (id) {
    this.id = id;
    this.actionQueue = [];

    this.move = asyncQueue(function (startTime) {

        var processTime = new Date() - startTime;
        // should be 1000 (give or take)

    }, function () { return 1000; });

    this.build = asyncQueue(function (startTime) {

        var processTime = new Date() - startTime;
        // shoudl be 6000 (give or take)

    }, function () { return 5000; });
}

Usage

var asyncQueue = require('habitants-async-queue');

asyncQueue(actionMethod, costMethod)

actionMethod is the function to be called.

costMethod is a function that returns how long to wait before calling actionMethod.

Installation

npm install habitants-async-queue

Tests

npm test
0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago