0.0.6 • Published 10 years ago

promise-lock v0.0.6

Weekly downloads
5
License
WTFPL
Repository
github
Last release
10 years ago

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'));
0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago