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

Fail tasks before while they are queued #75

Open
tynrol opened this issue Oct 22, 2024 · 1 comment
Open

Fail tasks before while they are queued #75

tynrol opened this issue Oct 22, 2024 · 1 comment

Comments

@tynrol
Copy link

tynrol commented Oct 22, 2024

Hello @alitto

I'm in need of feature to cancel tasks forsefully from pond queue, and there are ways to do it outside of pond but this is the prefered one. I'll gladly implement it myself, so the question is are you willing to integrate it in your project or i should implement it via fork?

@tynrol tynrol changed the title Fail tasks before while they are waiting Fail tasks before while they are queued Oct 22, 2024
@alitto
Copy link
Owner

alitto commented Oct 22, 2024

Hey @tynrol

As you point out, the best way to cancel a particular task at the moment is to pass a custom cancellable context to it directly in the function body, and cancel it from the outside, e.g.:

ctx, cancel := context.WithCancel(context.Background())

pool.Submit(func() {
  select {
    case <-ctx.Done():
        fmt.Println("task canceled")
    case <-taskCompleted:
  }
  return
})

cancel() // Cancel the task

I'd like to know more about your proposal, please share a code example here to discuss.
The preferred way to send contributions is via a fork of this repo.

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

2 participants