New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypeScript definition file #28
Conversation
Wonderful! Thank you! I'll review as soon as I can. |
|
||
declare module "bottleneck" { | ||
namespace Bottleneck { | ||
type Callback<T> = (err: any, result: T) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callback can return more than one result, but I understand that having to define
type Callback2<T,U> = (err: any, result1: T, result2: U) => void;
and then Callback3
and so on would make the whole thing exponentially complicated since submit()
and submitPriority()
are declared in a loop. If you think of a simple way to do it, please feel free to implement it :)
bottleneck.d.ts.ejs
Outdated
* Cancels all queued up requests and every added request will be automatically rejected. | ||
* @param interrupt - If true, prevent the requests currently running from calling their callback when they're done. Default: false. | ||
*/ | ||
stopAll(interrupt?: boolean): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stopAll
returns the limiter (type Bottleneck
)
bottleneck.d.ts.ejs
Outdated
/** | ||
* Changes the penalty value used by the BLOCK strategy. | ||
*/ | ||
changePenalty(penalty: number): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changePenalty
returns the limiter (type Bottleneck
)
bottleneck.d.ts.ejs
Outdated
* @param strategy - Which strategy to use if the queue gets longer than the high water mark. Default: Bottleneck.strategy.LEAK | ||
* @param rejectOnDrop - When true if a job is dropped its callback will be called with the first argument set to an Error object. If the job was a promise it will be rejected. Default: false | ||
*/ | ||
changeSettings(maxConcurrent?: number, minTime?: number, highWater?: number, strategy?: Bottleneck.Strategy, rejectOnDrop?: boolean): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changeSettings
returns the limiter (type Bottleneck
)
bottleneck.d.ts.ejs
Outdated
/** | ||
* Changes the reservoir count. | ||
*/ | ||
changeReservoir(reservoir: number): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changeReservoir
returns the limiter (type Bottleneck
)
bottleneck.d.ts.ejs
Outdated
* @param name - The event name. | ||
* @param fn - The callback function. | ||
*/ | ||
on(name: string, fn: Function): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the on()
methods return the limiter (type Bottleneck
)
bottleneck.d.ts.ejs
Outdated
/** | ||
* Adds to the reservoir count. | ||
*/ | ||
incrementReservoir(incrementBy: number): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incrementReservoir
returns the limiter (type Bottleneck
)
bottleneck.d.ts.ejs
Outdated
* Chain this limiter to another. | ||
* @param other - The limiter that requests to this limiter must also follow. | ||
*/ | ||
chain(other: Bottleneck): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chain
returns the limiter (type Bottleneck
)
Sorry for the long delay. This is beautiful! I've left a few comments. |
e3805d1
to
6e245b2
Compare
@SGrondin I have made the requested fixes and have updated the PR. |
Awesome! Thank you very much.
Any thoughts about this? |
It would be possible to generate signatures using nested loops for those cases, but it would be nasty code. I don't think that case is very interesting. I haven't seen any libraries that use callbacks with multiple return values and if multiple returns are needed in application code TypeScripts Tuple type support can be used. |
Good point! Thank you. |
Fixes #26
This change adds typescript definitions using an ejs template file to produce the overloads of
submit
andschedule
.I also added a
default
export from the module to improve interop with ES2015 modules and TypeScript import syntax.