itz-locking-time

0.1.2 • Public • Published

itz-locking-time

Use promise-based non-ipc locks

API

.runOnce(id, fnc, t): Run a function once or await it's current execution

  • id unique identifier
  • fnc() function that is going to be executed once or if it's already executing is being awaited
  • t: Throw or stay silent

.runNext(id, fnc, t): Run function or if already running run it again afterwards. Will automatically batch all next calls per iteration

  • id unique identifier
  • fnc() function that is going to be executed once or if it's already executing is being awaited
  • t: Throw or stay silent

Usage

const Lock = require('itz-locking-time')
const lock = Lock()
 
const wait = (i) => new Promise((resolve, reject) => setTimeout(resolve, i))
 
const someFnc = async () => {
  await wait(10000)
}
 
lock.runOnce('heavy', someFnc) // will run
await lock.runOnce('heavy', someFnc) // will await first execution
 
lock.runNext('process', someFnc) // will run
lock.runNext('process', someFnc) // will queue next execution
await lock.runNext('process', someFnc) // will await next execution

/itz-locking-time/

    Package Sidebar

    Install

    npm i itz-locking-time

    Weekly Downloads

    0

    Version

    0.1.2

    License

    MPL-2.0

    Unpacked Size

    3.26 kB

    Total Files

    4

    Last publish

    Collaborators

    • mkg20001