0.2.1 • Published 9 years ago

delaying_iterator v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Delaying iterators

This is are functions with delayed work.

Installation

    npm install delaying_iterator --save

Usage

    var delaying_iterator = require('delaying_iterator'),
      , d_map             = delaying_iterator.delaying_map
      , d_reduce          = delaying_iterator.delaying_reduce
      , promise
      ;

    // Using like basic functions

    promise = d_map([0,1,2,3], function(element, index) {
        return element + 1;
    });

    promise.then(function(result){
        console.log(result) // [1,2,3,4]
    });

    promise = d_reduce([1, 2, 3, 4], function(accumulator, element, index) {
        return accumulator + element;
    })

    promise.then(function(result){
        console.log(result) // 10
    })

    // Working with delay

    promise = d_map([0,1,2,3,4], function(el, iter) {
        return el + 1;
    }, 1000);

    promise( function(result) {
        console.log(result) // [1,2,3,4], each iteration will be completed with delay 1000ms
    });


    // working with noise

    promise = d_map([0,1,2,3,4], function(el, iter) {
        return el + 1;
    }, 1000, 1000);

    promise( function(result) {
        console.log(result) // [1,2,3,4], each iteration will be completed with delay 1000ms + Math.random() * 1000
    });

Tests

   npm test

License

MIT

0.2.1

9 years ago

0.2.0

9 years ago