-
Notifications
You must be signed in to change notification settings - Fork 419
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
Improve behaviour when posting to a shutdown thread pool #199
Conversation
If an executor has a handle_overflow method defined, use that in the case where we post to an executor which is not running. If no handle_overflow method is defined (e.g. for the single-thread executor), preserve the current behaviour of returning false. Fixes Github issue ruby-concurrency#192.
Improve behaviour when posting to a shutdown thread pool
Thank you for the PR! I definitely like this behavior better. Unfortunately, I realized after I merged the PR that the behavior for Honestly, I've never been overly fond of the term "overflow" in this context even though I'm the one who gave it that name. But I'm far less fond of Java's "rejected execution" terminology. We aren't really rejecting the task in most cases, just handling it differently. I'm comfortable renaming it to "fallback" (fallback_policy, can_fallback?, handle_fallback) or anything else that better represents the new behavior. |
Just a thought: we could move overflow/fallback handling in |
Yep, no problem - I'll take a look tomorrow. I was about to ask how you wanted me to handle the fact that Java*Executor classes don't have a |
Actually, on further reflection - now that it's a "fallback policy" rather than an "overflow policy", it's a bit more generally applicable. RubySingleThreadExecutor, for example, can't overflow, but you could still post to it after shutdown and require fallback behaviour. So I might:
|
👍 For backward compatibility we should probably still honor the Thank you! |
thank you for honoring the overflow_policy option for backwards compat! I am considering using concurrent-ruby in production code, and not sure if that's a safe move with concurrent-ruby's pre-1.0 status, but decisions like that will make more confident. |
@jrochkind I'm glad to hear you're considering using our work in production. I appreciate your concerns with the pre-1.0 status. We've been very careful with the various APIs and not making breaking changes. Most of our current plans are extensions to the existing APIs and internal improvements for performance (such as #197) or cleanser code (such as #176). I don't anticipate any breaking API changes in the foreseeable future. And as you can see, we try to be very transparent with such decisions so that everyone has a chance to weigh in. |
If an executor has a handle_overflow method defined, use that in the case where we post to an executor which is not running. If no handle_overflow method is defined (e.g. for the single-thread executor), preserve the current behaviour of returning false.
Fixes Github issue #192.
I've tested on MRI 2.0, but not on anything else yet (I'm hoping TravisCI will take care of some of that for me?).
I'm happy to apply any feedback (including any stylistic conventions I haven't spotted and followed), but had two specific questions:
post
returns false or throws an exception - is that OK or is there a nicer approach?