mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Fixed typo in timedLock function and added some missed methods * Added some tests for create helpers and timedLock method * Fixed lint issues
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import locks = require("locks");
|
|
|
|
// Mutex
|
|
const mutex: locks.Mutex = new locks.Mutex();
|
|
mutex.lock(() => {});
|
|
mutex.timedLock(1000, () => {});
|
|
if (mutex.tryLock()) { console.log('Should not happen'); }
|
|
mutex.unlock();
|
|
const createMutex: locks.Mutex = locks.createMutex();
|
|
|
|
// Semaphore
|
|
const semaphore: locks.Semaphore = new locks.Semaphore(1);
|
|
semaphore.wait(() => {});
|
|
semaphore.wait(() => {});
|
|
semaphore.signal();
|
|
const createSemaphore: locks.Semaphore = locks.createSemaphore(1);
|
|
|
|
// Read Write Lock
|
|
const readWriteLock: locks.ReadWriteLock = new locks.ReadWriteLock();
|
|
readWriteLock.readLock(() => {});
|
|
if (readWriteLock.tryReadLock()) { console.log('Should not happen'); }
|
|
readWriteLock.unlock();
|
|
readWriteLock.writeLock(() => {});
|
|
if (readWriteLock.tryWriteLock()) { console.log('Should not happen'); }
|
|
readWriteLock.unlock();
|
|
const createReadWriteLock: locks.ReadWriteLock = locks.createReadWriteLock();
|
|
|
|
// Conditional Variable
|
|
const condVariable: locks.CondVariable = new locks.CondVariable('ho');
|
|
if (condVariable.get() !== 'ho') { console.log('Should not happen'); }
|
|
condVariable.wait('hi', () => {});
|
|
condVariable.set('hi');
|
|
if (condVariable.get() !== 'hi') { console.log('Should not happen'); }
|
|
const createCondVariable: locks.CondVariable = locks.createCondVariable('ho');
|