Skip to content

coderofsalvation/iterate-with-delay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Loop over array but with time delay

Usage

npm install iterate-with-delay

Features

  • iterates over array or object but pauses inbetween
  • uses callback for each element
  • calls extra callback when done

Example: arrays

delay = require('iterate-with-delay')

arr = ["one","two","three"];

delay.each( arr, { time:1000 }, function(el,k){

  console.log( new Date()+"element received: "+k+" -> "+el );

},function(num){

  console.log("finished processing "+num+" items");

});

Example: objects

delay = require('iterate-with-delay')

arr = ["one","two","three"];

delay.each( arr, { time:1000 }, function(el,k){

  console.log( new Date()+"element received: "+k+" -> "+el );

},function(num){

  console.log("finished processing "+num+" items");

});

Example: wrapper

ms    = 500
delay = require('iterate-with-delay')
delayEach = function(arr,cb){
  delay arr, {time:ms}, cb
}

// now use delayEach in your application, and 
// use ms to control the delay on a global level

About

Relax! Loop over array and objects but with time delay

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published