if-not-running

0.0.15 • Public • Published

npm (scoped) npm bundle size (minified) Build Status

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

Readme

Keywords

none

Package Sidebar

Install

npm i if-not-running

Weekly Downloads

2

Version

0.0.15

License

Unlicense

Unpacked Size

7.24 kB

Total Files

6

Last publish

Collaborators

  • anwfr