habitants-async-queue

0.0.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i habitants-async-queue

Weekly Downloads

1

Version

0.0.3

License

MIT

Last publish

Collaborators

  • alexander-daniel