@salsita/lock

[![NPM version](https://img.shields.io/npm/v/@salsita/lock.svg)](https://www.npmjs.com/package/@salsita/lock) ![Downloads](https://img.shields.io/npm/dm/@salsita/lock.svg?style=flat) ![Licence](https://img.shields.io/npm/l/@salsita/lock.svg?style=flat) [!

Usage no npm install needed!

<script type="module">
  import salsitaLock from 'https://cdn.skypack.dev/@salsita/lock';
</script>

README

@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));