@nsfilho/unique
v0.1.9
Published
A very simple and small services to guarantee a `Unique Execution` of some piece of code (async) in a javascript / typescript applications.
Downloads
96
Readme
Unique Execution
A very simple and small services to guarantee a Unique Execution
of some piece of code (async) in
a javascript / typescript applications.
Environment Variables
This services use some environment variables to pre-adjust some things, like:
UNIQUE_START_DELAY
: define a minimum delay to startfunc
execution;UNIQUE_POOLING
: pooling time to check delayedfunc
to execute;
The delay time is a mininum
delay time, checked at UNIQUE_POOLING
interval.
Example
import { uniqueExecution } from '@nsfilho/unique';
/**
* Simple async function for example.
* Show a message after certain amount of time.
*/
const delayMessage = async (message: string, delay: number): Promise<void> =>
new Promise((resolve) => {
setTimeout(() => {
console.log(message);
resolve();
}, delay);
});
uniqueExecution({
name: __filename,
callback: async () => {
// execute a async func
await delayMessage('Hello World!!', 2000);
},
});