Socket
Socket
Sign inDemoInstall

timer-creator

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    timer-creator

A library to easy manage intervals and timeouts


Version published
Weekly downloads
3
decreased by-91.67%
Maintainers
1
Install size
46.4 kB
Created
Weekly downloads
 

Readme

Source

Timer Creator

What is this?

A simple library to manage timeouts and intervals.

How to use it?

First you need to import it in your project

The require way

let { createInterval, destroyInterval, TimeUnit } = require("timer-creator");

The import way

import { createTimeout, destroyTimeout, TimeUnit } from "timer-creator";

Then use it to establish a periodic callback execution until condition

  import { createInterval, destroyInterval, TimeUnit } from "timer-creator";

  const TIMER_NAME = 'myIntervalName'

  function myFunction() {
    // YOUR OWN CODE AND STUFF
    hasConditionMeeted && destroyInterval(TIMER_NAME)
  }

  createInterval(TIMER_NAME, myFunction, 2 * TimeUnit.MINUTE)

Or one time callback execution

  import { createTimeout, TimeUnit } from "timer-creator";

  function myFunction(arg1, arg2) {
    // YOUR OWN CODE AND STUFF
  }

  createTimeout('myTimeoutName', myFunction, 30 * TimeUnit.SECOND, [arg1, arg2])
Additional JSDOC info

JSDOC

Table of Contents
TimeUnit

Contains time unit constants

Type: object

MILISECOND

Time unit referent to Milisecond

Type: number

SECOND

Time unit referent to Second in miliseconds

Type: number

MINUTE

Time unit referent to Minute in miliseconds

Type: number

HOUR

Time unit referent to Hour in miliseconds

Type: number

DAY

Time unit referent to Day in miliseconds

Type: number

existInterval

Checks whether exist interval with given name.

Parameters

Returns boolean true or false wheter interval is stored or not

getInterval

Retrieves interval value for given name.

Parameters

Returns number interval number reference

createInterval

Creates and _store interval object with given name, to execute callback function on the waitTime specified with given args.

Parameters
  • name string interval name
  • callback Function the function to be executed as a callback
  • waitTime number the waiting time for the interval
  • args (string | Array | null) arguments to be passed to the callback function
destroyInterval

Destroy interval with given name and removes it from _store.

Parameters
existTimeout

Checks whether exist timeout with given name.

Parameters

Returns boolean true or false wheter timeout is stored or not

getTimeout

Retrieves timeout value for given name.

Parameters

Returns number timeout number reference

createTimeout

Creates and store timeout object with given name, to execute callback function on the waitTime specified with given args, its removed from store when callback is executed.

Parameters
  • name string timeout name
  • callback Function the function to be executed as a callback
  • waitTime number the waiting time for the timeout
  • args (string | Array | null) arguments to be passed to the callback function
destroyTimeout

Destroy timeout with given name and removes it from store.

Parameters

TimeUnit

Contains time unit constants

Type: Object

MILISECOND

Time unit referent to Milisecond

Type: number

SECOND

Time unit referent to Second in miliseconds

Type: number

MINUTE

Time unit referent to Minute in miliseconds

Type: number

HOUR

Time unit referent to Hour in miliseconds

Type: number

DAY

Time unit referent to Day in miliseconds

Type: number

existInterval

Checks whether exist interval with given name.

Parameters

Returns boolean true or false wheter interval is stored or not

getInterval

Retrieves interval value for given name.

Parameters

Returns number interval number reference

createInterval

Creates and _store interval object with given name, to execute callback function on the waitTime specified with given args.

Parameters
  • name string interval name
  • callback Function the function to be executed as a callback
  • waitTime number the waiting time for the interval
  • args (string | Array | null) arguments to be passed to the callback function

destroyInterval

Destroy interval with given name and removes it from _store.

Parameters

existTimeout

Checks whether exist timeout with given name.

Parameters

Returns boolean true or false wheter timeout is stored or not

getTimeout

Retrieves timeout value for given name.

Parameters

Returns number timeout number reference

createTimeout

Creates and store timeout object with given name, to execute callback function on the waitTime specified with given args, its removed from store when callback is executed.

Parameters
  • name string timeout name
  • callback Function the function to be executed as a callback
  • waitTime number the waiting time for the timeout
  • args (string | Array | null) arguments to be passed to the callback function

destroyTimeout

Destroy timeout with given name and removes it from store.

Parameters

Keywords

FAQs

Last updated on 06 Mar 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc