@salsita/lock

1.0.1 • Public • Published

@salsita/lock

NPM version Downloads Licence Dependency Status devDependency Status

Function to create lock function. This lock function can be used to wrap any async function ensuring it will not be executed again before previous call finish.

Example:

const createLock = require("@salsita/lock");

const lock = createLock();

const wait = timeout => new Promise(resolve => setTimeout(resolve, timeout));
const fn = async n => {
  await wait(1000);
  console.log(`work ${n} done`);
};

lock(() => fn(1));
lock(() => fn(2));

Readme

Keywords

none

Package Sidebar

Install

npm i @salsita/lock

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

1.64 kB

Total Files

3

Last publish

Collaborators