timeout-unify

1.0.1 • Public • Published

Timeout unify

Unifier and reseter of timeout calls in sequence by key. Handling parallel event concurrency and grouping.

const timeoutUnify = require('timeout-unify');
timeoutUnify.add('eventX', someValue, allValues => {
	/* DO SOME */
}, 3000);

add function:

Create or replace timeout adding new value.

Arguments:

  • key, string to control event name.
  • value, some value to get at final.
  • callback, function to run at the end of time.
  • time, time in milliseconds for the final timeout (like setTimeout).

Return:

  • Boolean, already existed or not.

Example:

for (let index = 0; index < 50; index++) {
	const isFirst = timeoutUnify.add('myfor', index, indexes => {
		console.log(indexes);
	}, 300);
}

get function:

Get last and current setTimeout.

Arguments:

  • key, string to control event name

Return:

Example:

// get last timeout
const lasTimeoutInteger = timeoutUnify.get('myfor');
console.log(lasTimeoutInteger);

cancel function:

Cancel timeout by key

Arguments:

  • key, string to control event name

Return:

  • Boolean, already existed or not.

Example:

// cancelling
const isExists = timeoutUnify.cancel('myfor');

People

Fellipe Paiva 😎

Readme

Keywords

Package Sidebar

Install

npm i timeout-unify

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

2.87 kB

Total Files

4

Last publish

Collaborators

  • fellipepaiva