Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiscodev/timer-creator
A simple library to manage timeouts and intervals.
https://github.com/xiscodev/timer-creator
interval javascript library timeout timer-manager
Last synced: 1 day ago
JSON representation
A simple library to manage timeouts and intervals.
- Host: GitHub
- URL: https://github.com/xiscodev/timer-creator
- Owner: xiscodev
- Created: 2020-03-03T07:08:13.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-06T15:37:05.000Z (almost 4 years ago)
- Last Synced: 2024-12-23T11:53:14.950Z (26 days ago)
- Topics: interval, javascript, library, timeout, timer-manager
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/timer-creator
- Size: 56.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
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_
```js
let { createInterval, destroyInterval, TimeUnit } = require("timer-creator");
```_The import way_
```js
import { createTimeout, destroyTimeout, TimeUnit } from "timer-creator";
```Then use it to establish a periodic callback execution until condition
```js
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
```js
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](#timeunit)
- [MILISECOND](#milisecond)
- [SECOND](#second)
- [MINUTE](#minute)
- [HOUR](#hour)
- [DAY](#day)
- [existInterval](#existinterval)
- [Parameters](#parameters)
- [getInterval](#getinterval)
- [Parameters](#parameters-1)
- [createInterval](#createinterval)
- [Parameters](#parameters-2)
- [destroyInterval](#destroyinterval)
- [Parameters](#parameters-3)
- [existTimeout](#existtimeout)
- [Parameters](#parameters-4)
- [getTimeout](#gettimeout)
- [Parameters](#parameters-5)
- [createTimeout](#createtimeout)
- [Parameters](#parameters-6)
- [destroyTimeout](#destroytimeout)
- [Parameters](#parameters-7)#### TimeUnit
Contains time unit constants
Type: [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
##### MILISECOND
Time unit referent to Milisecond
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
##### SECOND
Time unit referent to Second in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
##### MINUTE
Time unit referent to Minute in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
##### HOUR
Time unit referent to Hour in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
##### DAY
Time unit referent to Day in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
#### existInterval
Checks whether exist interval with given name.
##### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true or false wheter interval is stored or not
#### getInterval
Retrieves interval value for given name.
##### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
- `callback` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the function to be executed as a callback
- `waitTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the waiting time for the interval
- `args` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | null)** arguments to be passed to the callback function#### destroyInterval
Destroy interval with given name and removes it from \_store.
##### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
#### existTimeout
Checks whether exist timeout with given name.
##### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true or false wheter timeout is stored or not
#### getTimeout
Retrieves timeout value for given name.
##### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name
- `callback` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the function to be executed as a callback
- `waitTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the waiting time for the timeout
- `args` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | null)** arguments to be passed to the callback function#### destroyTimeout
Destroy timeout with given name and removes it from store.
##### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name
### TimeUnit
Contains time unit constants
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
#### MILISECOND
Time unit referent to Milisecond
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
#### SECOND
Time unit referent to Second in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
#### MINUTE
Time unit referent to Minute in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
#### HOUR
Time unit referent to Hour in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
#### DAY
Time unit referent to Day in miliseconds
Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
### existInterval
Checks whether exist interval with given name.
#### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true or false wheter interval is stored or not
### getInterval
Retrieves interval value for given name.
#### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
- `callback` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the function to be executed as a callback
- `waitTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the waiting time for the interval
- `args` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | null)** arguments to be passed to the callback function### destroyInterval
Destroy interval with given name and removes it from \_store.
#### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** interval name
### existTimeout
Checks whether exist timeout with given name.
#### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true or false wheter timeout is stored or not
### getTimeout
Retrieves timeout value for given name.
#### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name
- `callback` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the function to be executed as a callback
- `waitTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the waiting time for the timeout
- `args` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | null)** arguments to be passed to the callback function### destroyTimeout
Destroy timeout with given name and removes it from store.
#### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** timeout name