-
Notifications
You must be signed in to change notification settings - Fork 39
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
Canceling a pool #24
Comments
@Christilut Hey Christiaan, cancelling a pool is possible with a bit of manual work. At this point, there’s no method allowing you to manually stop the pool. What you can do as a workaround is throwing a custom error, like Here’s a sample setup that may work for you: try {
const errors = []
const { results } = await PromisePool
.for(users)
.handleError(async (error, user) => {
if (error instanceof CancelPoolError) {
throw error // Uncaught errors will stop the promise pool
}
errors.push(error) // you must collect errors yourself
})
.process(async data => {
if (canceled) {
throw new CancelPoolError()
}
// your processing
})
await handleCollected(errors) // this may throw
return { results }
} catch (error) {
// this should only be reached when the CancelPoolError was thrown
} I’m happy to review and support you with a pull request. I won’t have time to implement a |
Thanks for the super quick response :) I'll use your workaround for now, it does the trick nicely. |
Sweet! I'll close this issue and open a new one for the "stopping the pool" feature. |
Awesome! Appreciate the quick and helpful response :) |
@Christilut You’re welcome! :) |
I'm running a pool that takes a while, is there any way to cancel it?
I guess I can do a workaround like this:
But that would still iterate all input elements for nothing.
The text was updated successfully, but these errors were encountered: