Skip to content
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

Allow to specify type definition for the limit funciton. #23

Open
giovannibenussi opened this issue Jun 21, 2024 · 0 comments
Open

Allow to specify type definition for the limit funciton. #23

giovannibenussi opened this issue Jun 21, 2024 · 0 comments

Comments

@giovannibenussi
Copy link

I'm using a queue to limit the concurrency for API calls in different functions that have different types, so the following doesn't work for us (simplified for example purposes):

const limit = promiseLimit<number | string>(2);
limit(1) // Argument of type 'number' is not assignable to parameter of type '() => Promise<string | number>'

I would like to keep a single queue for all my functions because all of them performs an API call, so I want to limit them.

For now I need to set the type to any, but we loose type safety while doing so. It would be nice to be able to define this type when calling the limit function like this:

const limit = promiseLimit(2);
limit<number>(1)
limit<string>('hi')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant