delaying_iterator

0.2.1 • Public • Published

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

/delaying_iterator/

    Package Sidebar

    Install

    npm i delaying_iterator

    Weekly Downloads

    1

    Version

    0.2.1

    License

    MIT

    Last publish

    Collaborators

    • dex157