async-lock: Generics in returned values (#23131)

* async-lock: Generics in returned values

* Revert promise with "done" test to prove it still works as before

* Add test where fn is a promise
This commit is contained in:
Alejandro Fernández Haro
2018-01-29 20:26:24 +00:00
committed by Sheetal Nandi
parent 257c8bc48a
commit 7968b99ad1
3 changed files with 19 additions and 7 deletions

View File

@@ -10,6 +10,14 @@ lock.acquire("key", (done) => {
done();
}).then(() => { /* ... */ });
lock.acquire("key", () => "stringValue")
// Check returned value's type is inherited properly
.then((str) => str.replace("s", "S"));
lock.acquire("key", async () => "stringValue")
// Check returned value's type is inherited properly
.then((str) => str.replace("s", "S"));
lock.acquire([ "key1", "key2" ], (done) => {
done();
}, (err, ret) => { /* ... */ });

View File

@@ -1,11 +1,12 @@
// Type definitions for async-lock
// Project: https://github.com/rain1017/async-lock
// Definitions by: Elisée MAURER <https://github.com/elisee>
// Definitions by: Elisée MAURER <https://github.com/elisee>, Alejandro <https://github.com/afharo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
interface AsyncLockDoneCallback {
(err?: Error, ret?: any): void;
interface AsyncLockDoneCallback<T> {
(err?: Error, ret?: T): void;
}
interface AsyncLockOptions {
@@ -18,8 +19,13 @@ interface AsyncLockOptions {
declare 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>;
acquire<T>(key: string | string[],
fn: (() => T | PromiseLike<T>) | ((done: AsyncLockDoneCallback<T>) => any),
opts?: AsyncLockOptions): PromiseLike<T>;
acquire<T>(key: string | string[],
fn: (done: AsyncLockDoneCallback<T>) => any,
cb: AsyncLockDoneCallback<T>,
opts?: AsyncLockOptions): void;
isBusy(): boolean;
}

View File

@@ -8,13 +8,11 @@
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,