diff --git a/async-lock/async-lock-tests.ts b/async-lock/async-lock-tests.ts new file mode 100644 index 000000000..d3eedf2fd --- /dev/null +++ b/async-lock/async-lock-tests.ts @@ -0,0 +1,22 @@ +/// + +import * as AsyncLock from "async-lock"; +const lock = new AsyncLock(); + +lock.acquire("key", (done) => { + done(); +}, (err, ret) => { /* ... */ }); + +lock.acquire("key", (done) => { + done(); +}).then(() => { /* ... */ }); + +lock.acquire([ "key1", "key2" ], (done) => { + done(); +}, (err, ret) => { /* ... */ }); + +lock.isBusy(); + +const lock2 = new AsyncLock({ timeout : 5000 }); +const lock3 = new AsyncLock({ maxPending : 5000 }); +const lock4 = new AsyncLock({ Promise: null }); diff --git a/async-lock/async-lock.d.ts b/async-lock/async-lock.d.ts new file mode 100644 index 000000000..e5f8613c7 --- /dev/null +++ b/async-lock/async-lock.d.ts @@ -0,0 +1,30 @@ +// Type definitions for async-lock +// Project: https://github.com/rain1017/async-lock +// Definitions by: Elisée MAURER +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "async-lock" { + interface AsyncLockDoneCallback { + (err?: Error, ret?: any): void; + } + + interface AsyncLockOptions { + timeout?: number; + maxPending?: number; + domainReentrant?: boolean; + Promise?: any; + } + + class AsyncLock { + constructor(options?: AsyncLockOptions); + + acquire(key: string|string[], fn: (done: AsyncLockDoneCallback) => any, cb: AsyncLockDoneCallback, opts?: AsyncLockOptions): void; + acquire(key: string|string[], fn: (done: AsyncLockDoneCallback) => any, opts?: AsyncLockOptions): PromiseLike; + + isBusy(): boolean; + } + + namespace AsyncLock {} + + export = AsyncLock; +}