mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Add definition file for async-lock
This commit is contained in:
22
async-lock/async-lock-tests.ts
Normal file
22
async-lock/async-lock-tests.ts
Normal 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
30
async-lock/async-lock.d.ts
vendored
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user