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

feat: allow generic when creating Piscina #569

Merged
merged 2 commits into from
May 20, 2024
Merged

feat: allow generic when creating Piscina #569

merged 2 commits into from
May 20, 2024

Conversation

alexframe
Copy link
Contributor

@alexframe alexframe commented May 20, 2024

Add ability to pass Task and Return type when creating Piscina class.

Example usage:

const pool = new Piscina<MyTask, MyResult>();

// result resolves as `MyResult` and the args is expected to be a `MyTask`
const result = await pool.run({ my: 'task' }); 

Resolves #231.

@alexframe alexframe changed the title feat: allow generic when creating Priscina feat: allow generic when creating Piscina May 20, 2024
@alexframe alexframe marked this pull request as ready for review May 20, 2024 08:49
Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some testing to it?

@alexframe
Copy link
Contributor Author

@metcoder95 I have added a couple of tests, two of which are annotated with @ts-expect-error to ensure that an error is thrown by typescript when an incorrect type is assigned.

Let me know if there's anything else you think is needed.

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! LGTM

@metcoder95 metcoder95 merged commit 108440c into piscinajs:current May 20, 2024
10 checks passed
@alexframe alexframe deleted the feat/priscina-generic branch May 20, 2024 10:21
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

Successfully merging this pull request may close these issues.

Use generic Piscina class to typecheck run() parameters and return type.
2 participants