-
-
Notifications
You must be signed in to change notification settings - Fork 40
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: add clear_tasks()
#69
feat: add clear_tasks()
#69
Conversation
a32df2b
to
e0061d5
Compare
@samangh Hello! 👋 Thank you for the kind words and the PR! This is an interesting feature/use case and not something I had considered in the past. It looks like the changes are simple, but I agree that this could cause some issues in practice with race conditions. At a minimum, for me to consider merging this PR, I would appreciate it if you could add some unit tests for the new feature. Both for the queue and the thread pool. Thanks! |
@DeveloperPaul123 Thanks for the reply. I've added unit tests to both the queue and the thread pool, I hope they make sense. |
5648a19
to
62cecbe
Compare
@samangh Looks like most of the CI builds are failing due to some warnings. Could you please address these? |
Quality Gate passedIssues Measures |
ae1526b
to
43d2d29
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #69 +/- ##
==========================================
+ Coverage 98.07% 98.52% +0.45%
==========================================
Files 2 2
Lines 104 136 +32
==========================================
+ Hits 102 134 +32
Misses 2 2 ☔ View full report in Codecov by Sentry. |
43d2d29
to
11976ab
Compare
@DeveloperPaul123 Thanks for letting me know. I've fixed the tests, they should pass now. |
11976ab
to
4a853e1
Compare
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.
Looks good to me! Nice work 👍
@DeveloperPaul123 Firstly, thanks for this nice library. I'm glad that mentioned it on reddit. I was thinking of implementing my own thread pool, but you've definitely done a better job than I could have!
I think it would be useful to have a function for clearing all the tasks in the thread pool. This could be useful when, for example, one loads the thread pool with a list of tasks but then needs to clear them if an error/exception is thrown somewhere.
Note that this not fool-proof, for example a running task could add other tasks to the pool. Or alternatively, during the
for
loop, one thread (which just had it's task list cleared) could steal a thread from another task. But I didn't see a way of getting around these edge cases without adding another mutexOf course, this is just one possible way of doing this. Please feel to do with the PR as you wish :-).