Namespace: Timers:ploop

Timers:ploop

Source:

Methods

ploop(ms, callback, oldLoopopt, nullable) → {Object}

Setup a loop for repeated execution of a callback, kills old loop if wished to prevent overlapping loops. This implementation uses Date.now()/Date.getTime() to improve on timer precision for long running loops.

Warning: these timers are more precise than normal timer for long time spans and less precise for short ones, if you are dealing with times at least above 30s (or minutes and hours) this the right choice, if you look to use precise timers in the second and millisecond range, definitely use schedule/loop instead!

The loops of this method can also be used in countermand(). This method does not actually use intervals internally but timeouts, so don't wonder if you can't find the ids in JS.

Parameters:
Name Type Attributes Default Description
ms Number

time in milliseconds until execution

callback function

callback function to execute after ms

oldLoop Object | Number <optional>
<nullable>
null

if set, kills the loop before setting up new one

Source:
See:
Throws:

error if ms is not positive or if callback is not a function

Returns:
loop (if you give an old loop into the function the same reference will be returned)
Type
Object
Example
const loop = ploop(250, function(){ document.body.classList.add('brightred'); });
const loop = ploop(100, function(){ document.body.classList.add('brightgreen'); }, loop);