@aymandev/pausabletimers

Timers that can be paused and resumed unlike default setTimeout and setInterval

Usage no npm install needed!

<script type="module">
  import aymandevPausabletimers from 'https://cdn.skypack.dev/@aymandev/pausabletimers';
</script>

README

PausableTimers

Build Status Repo Size License npm

Getting Started

Installation

npm install @aymandev/pausabletimers

How to use this timers?

Almost same as default setTimeout and setInterval. First need to declare timer variable:

const timer = setPausableTimeout(() => console.log("message"), 5000);

This timeout will execute after 5 seconds.

How to use interval timer?

Just have to change function name little bit:

const timer = setPausableInterval(() => console.log("message"), 5000);

How to pause timer?

Just have to call method from timer:

timer.pauseTimer();

Also you can pause timer for N milliseconds:

timer.pauseTimer(3000); // Timer will unpause after 3 seconds

How to unpause timer?

Just have to call method from timer:

timer.startTimer();