diff --git a/types/rwlock/index.d.ts b/types/rwlock/index.d.ts new file mode 100644 index 0000000000..a7611f22da --- /dev/null +++ b/types/rwlock/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for RWLock v5.0.0 +// Project: https://github.com/71104/rwlock +// Definitions by: Federico Caselli +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class ReadWriteGeneric { + readLock(callback: T, options?: ReadWriteLock.Options): void; + readLock(key: string, callback: T, options?: ReadWriteLock.Options): void; + writeLock(callback: T, options?: ReadWriteLock.Options): void; + writeLock(key: string, callback: T, options?: ReadWriteLock.Options): void; +} +declare namespace ReadWriteLock { + type Release = () => void; + + type Callback = (release: Release) => void; + + type AsyncCallback = (err: Error, release: Release) => void; + + interface Options { + scope?: any; + timeout?: number; + timeoutCallback(): void; + } +} + +declare class ReadWriteLock extends ReadWriteGeneric { + constructor(); + async: ReadWriteGeneric; +} +export = ReadWriteLock; diff --git a/types/rwlock/rwlock-tests.ts b/types/rwlock/rwlock-tests.ts new file mode 100644 index 0000000000..8e2f210164 --- /dev/null +++ b/types/rwlock/rwlock-tests.ts @@ -0,0 +1,7 @@ +// Original test file https://github.com/71104/rwlock/blob/master/test/all.js +import * as ReadWriteLock from 'rwlock'; + +const lock = new ReadWriteLock(); +lock.readLock((release) => { + release(); +}); diff --git a/types/rwlock/tsconfig.json b/types/rwlock/tsconfig.json new file mode 100644 index 0000000000..d5eefd893d --- /dev/null +++ b/types/rwlock/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rwlock-tests.ts" + ] +} \ No newline at end of file diff --git a/types/rwlock/tslint.json b/types/rwlock/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/types/rwlock/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }