0.2.1 • Published 5 years ago

space-lock v0.2.1

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

Lock.js

Travis Build Status

Lock asynchronous resources, uses native Promises. 🔒

Install

npm i -s Pandorym/SpaceLock

Usage

import { Ymir } from 'space-lock';

let ymir = new Ymir();

ymir.checkIn('KEY')
    .then(() => {
        // console.log('1');
    })
    .then(() => {
        // console.log('  wait 500ms');
        setTimeout(() => {
            ymir.checkOut('KEY');
            // console.log('  checkOut');
        }, 500);
    });

ymir.doOnce('KEY', async () => {
    // console.log('2');
    // console.log('  wait 1000ms')
    
    return new Promise((resolve => {
        setTimeout(resolve, 1000)
    }))
});

ymir.checkIn('KEY')
    .then(() => {
        // console.log('3');
    });

// output
//   1
//     wait 500ms
//     checkout
//   2
//     wait 1000ms
//   3
0.2.1

5 years ago