🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

timeoutcontrol

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timeoutcontrol

A JavaScript tool to control setTimeout operations.

latest
Source
npmnpm
Version
1.1.3
Version published
Weekly downloads
18
350%
Maintainers
1
Weekly downloads
 
Created
Source

TimeoutControl

A JavaScript tool to imitate setTimeout functionality to extend control over it.

Installation

NPM

npm install timeoutcontrol

Usage

TimeoutControl accepts any parameters that the native setTimeout will accept.

const timeout = new TimeoutControl(callback[, delay[, param1, param2, ...]]);

Properties

.id

Returns the id of the timeout.

.params

Returns an array of all params (i.e., param1, param2, ...).

.duration

Returns the duration of the timeout.

.timeStart

Returns the time the timeout starts.

.timeStop

Returns the time the timeout is paused/stopped.

.callback

Returns the callback function to run when the timeout ends.

.timeLeft

Returns the time left before the timeout ends.

.done

Returns a boolean of whether the timeout has ended.

Methods

.pause()

Pause the ongoing timeout.

.resume()

Resume the paused timeout.

.restart()

Clear the timeout, then start the timeout with the arguments previously passed to the instance.

.clear()

Cancel the timeout.

Demo

const duration = 5000;
const callback = function(){
    console.log(...arguments);
}

const timeout = new TimeoutControl(callback, duration, 1, 2, 3, 4, 5);

/* ...SOME OPERATIONS / CONDITIONS */

timeout.pause();

/* ...SOME OPERATIONS / CONDITIONS */

timeout.resume();

/* ...SOME OPERATIONS / CONDITIONS */

timeout.clear();

/* ...SOME OPERATIONS / CONDITIONS */

timeout.restart();

Keywords

setTimeout

FAQs

Package last updated on 24 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts