promise-lock

0.0.6 • Public • Published

promise-lock

NPM Version Build Status

Installation

npm install promise-lock

Usage

  1. Rejecting concurrent promises
    const lock = new PromiseLock();
 
    lock.on($.get('/foo'))
        .then((res)=>console.log(res))       //<-- will log the result
        .catch((res)=>console.log('Error'));
 
    lock.on($.get('/bar'))
        .then((res)=>console.log(res))
        .catch((res)=>console.log('Error'));//<-- will log "Error", because the lock is previously set on anothe promise
  1. Cancelling previously started promise
    const lock = new PromiseLock();
 
    lock.on($.get('/foo'))
        .then((res)=>console.log(res))       //<-- will never run
        .catch((res)=>console.log('Error')); //<-- will never run
    
    lock.cancel();
 
    lock.on($.get('/bar'))
        .then((res)=>console.log(res))       //<-- will log the result
        .catch((res)=>console.log('Error'));

Readme

Keywords

none

Package Sidebar

Install

npm i promise-lock

Weekly Downloads

2

Version

0.0.6

License

WTFPL

Last publish

Collaborators

  • corporateanon