Micro library to queue delayed callbacks.
bower install sequenza# or npm install sequenza
It uses requestAnimationFrame
with a fallback for setInterval
.
You may use it in the browser and with Node, under AMD, CommonJS or as a regular script.
Usage
Choose between three different ways to instantiate:
step1 step2 ...stepNstartoptions;
var steps = step1 step2 ...stepN; stepsstartoptions;
var sequenza = sequenza;sequenza;sequenza; sequenzastartoptions;
A step may be an object that contains at least one of these properties:
callback: Function delay: Number
But you may also pass a callback or a delay directly as a step.
Also, you may pass an options object to the start
method, these are the available options:
iterations
the number of times the sequence should be iterated, defaults to 1. to iterate forever, just assignInfinity
to it.
Example
// create an instance var sequenza = ; // queue some steps sequenza; sequenza; sequenza; // start it sequenzastart iterations: 3;
The above snippet will take ≈ 1 second to log each number, then it's going to repeat 2 more times.
You may also use Sequenza as a clock, to call a function between certain amount of time:
var ticks = 0; var { console;}; callback: tick delay: 1000start iterations: Infinity;