-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow exra args and use default export in TypeScript
[fixes #55] BREAKING CHANGE: If using TypeScript you must upgrade to at least TypeScrTypeScript@3 BREAKING CHANGE: If using TypeScript, swap: ```ts import throat = require('throthroat'); ``` to ```ts import throat from 'throat'; ```
- Loading branch information
1 parent
1c6a45b
commit 871d501
Showing
5 changed files
with
39 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
declare function throat<TResult, TFn extends (...args: Array<any>) => Promise<TResult>>(size: number, fn: TFn): TFn; | ||
declare function throat<TResult, TFn extends (...args: Array<any>) => Promise<TResult>>(fn: TFn, size: number): TFn; | ||
declare function throat(size: number): <TResult>(fn: () => Promise<TResult>) => Promise<TResult>; | ||
/** | ||
* Throttle the given function to only run `size` times in parallel. | ||
* Extra calls will be queued until one of the earlier calls completes. | ||
*/ | ||
declare function throat<TResult, TArgs extends any[]>( | ||
size: number, | ||
fn: (...args: TArgs) => Promise<TResult> | ||
): (...args: TArgs) => Promise<TResult>; | ||
|
||
/** | ||
* Throttle the given function to only run `size` times in parallel. | ||
* Extra calls will be queued until one of the earlier calls completes. | ||
*/ | ||
declare function throat<TResult, TArgs extends any[]>( | ||
fn: (...args: TArgs) => Promise<TResult>, | ||
size: number | ||
): (...args: TArgs) => Promise<TResult>; | ||
|
||
/** | ||
* Create a throttle that only allows `size` calls in parallel. | ||
* Extra calls will be queued until one of the earlier calls completes. | ||
* | ||
* To create an exclusive lock, just use a `size` of `1`. | ||
*/ | ||
declare function throat( | ||
size: number | ||
): <TResult, TArgs extends any[] = []>( | ||
fn: (...args: TArgs) => Promise<TResult>, | ||
...args: TArgs | ||
) => Promise<TResult>; | ||
export default throat; | ||
|
||
export = throat; // get typings via: import throat = require("throat") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters