0.0.6 • Published 9 years ago
promise-lock v0.0.6
promise-lock
Installation
npm install promise-lock
Usage
- 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
- 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'));