Namespace: Timers:pschedule

Timers:pschedule

Source:

Methods

pschedule(ms, callback, oldTimeropt, nullable) → {Object}

Setup a timer for one-time execution of a callback, kills old timer if given to prevent overlapping timers. This implementation uses Date.now()/Date.getTime() to improve on timer precision for long running timers. The timers of this method can also be used in countermand().

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!

Parameters:
Name Type Attributes Default Description
ms Number

time in milliseconds until execution

callback function

callback function to execute after ms

oldTimer Object | Number <optional>
<nullable>
null

if set, kills the timer before setting up new one

Source:
See:
Throws:

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

Returns:
timer (does not create new timer object if oldTimer given, but returns old one)
Type
Object
Example
const timer = pschedule(1000, function(){ alert('time for tea'); });
const timer = pschedule(2000, function(){ alert('traffic jam, tea has to wait'); }, timer);