if-not-running
Run JS function if it's not running currently.
Usage
Parameters:
- unique identifier
- process to run (supports synchronous and asynchronous functions).
Returns: value returned from process
Example
import ifNot from 'if-not-running'
const job = () => {
// long job...
}
ifNot.run('foo', job) // run
ifNot.run('foo', job) // don't run (still running)
ifNot.run('anotherJob', job) // run
ifNot.run('anotherJob', job) // don't run (still running)
// when job finished...
ifNot.run('foo', job) // run
ifNot.run('anotherJob', job) // run
Supports synchronous processes:
const job = () => {
// long job...
return 123
}
const result = ifNot.run('foo', job) // result = 123
As well as asynchronous processes:
// process can be asynchronous
const job = () => {
return new Promise((resolve, reject) => {
// long job...
resolve(123)
})
}
ifNot.run('foo', job).then(result => {
// result = 123
})
Development
Running tests
yarn
yarn test
yarn test --watch
Dev mode
yarn watch