Add definition file for async-lock

This commit is contained in:
Elisée Maurer
2016-03-16 09:36:59 +01:00
parent 2f47c75835
commit 3721bf1f5a
2 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
/// <reference path="async-lock.d.ts" />
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 });

30
async-lock/async-lock.d.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
// Type definitions for async-lock
// Project: https://github.com/rain1017/async-lock
// Definitions by: Elisée MAURER <https://github.com/elisee/>
// 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<any>;
isBusy(): boolean;
}
namespace AsyncLock {}
export = AsyncLock;
}