-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add new types of behavior for when the ScheduledThreadPool
is dropped
#17
Conversation
This seems pretty reasonable to me, though I think it'd be better to use a builder rather than adding even more constructor variants. |
…eates a `ScheduledThreadPool` with the provided name, number of threads, and the desired behavior in relation to pending scheduled executions when the pool is dropped. This on drop behavior is specified using the new `OnPoolDropBehavior` enum. The existing behavior (and the default) is specified as `CompletePendingScheduled`. This means that all pending scheduled executions will be run, but periodic actions will not be rescheduled once these have completed. The other option is `DiscardPendingScheduled`. As the name suggests, this behavior means that any pending scheduled executions will be discarded (not run).
8e190cc
to
5f8ea0e
Compare
I've updated the PR to remove the I don't know if it makes sense to have a default value for the number of threads when using the builder, which is what I've done for now (with a default value of 2), or if it makes more sense to do something like rename |
There are a few options:
|
…lder pattern to configure a new pool. This builder pattern must be used if you wish to control the behavior of the pool when it's dropped (via the builder's `on_drop_behavior` method).
a765cab
to
88af1c9
Compare
I've updated things again. I've essentially gone with what you described in option 4 but have named the Let me know what you think. |
@sfackler is there anything I can do to help get this merged? |
Nope, sorry for the delay! |
I ended up switching to a staged builder after thinking about it a bit more, but it's published now |
Add
ScheduledThreadPool::with_name_and_drop_behavior
method that creates aScheduledThreadPool
with the provided name, number of threads, and the desiredbehavior in relation to pending scheduled executions when the pool is dropped.
This on drop behavior is specified using the new
OnPoolDropBehavior
enum.The existing behavior (and the default) is specified as
CompletePendingScheduled
. This means that all pending scheduled executionswill be run, but periodic actions will not be rescheduled once these have
completed.
The other option is
DiscardPendingScheduled
. As the name suggests, thisbehavior means that any pending scheduled executions will be discarded (not
run).
Introduce a
ScheduledThreadPoolBuilder
type that allows using a builderpattern to configure a new pool.
This builder pattern must be used if you wish to control the behavior of the
pool when it's dropped (via the builder's
on_drop_behavior
method).Fix a docs typo
For what it's worth, I don't love the newUpdated to add awith_name_and_drop_behavior
method. I was tempted to add a builder pattern, of sorts, but didn't want to bloat the scope of this PR before getting feedback on this smaller change. As things stand the public API hasn't changed other than with the addition ofwith_name_and_drop_behavior
.ScheduledThreadPoolBuilder
For more context, the motivation for taking a look into this is sfackler/r2d2#99. The
reap_connections
scheduled executions there mean that the threads are kept alive for 30s after the pool has been dropped (in the worst case). This is unfortunate especially seeing as theSharedPool
in r2d2 would have already been long dropped by the time the scheduled execution ended up being run and so theNone
path of this code would get hit: https://github.com/sfackler/r2d2/blob/1178d1805dda0ec08f9cec626a67575691c0ce8f/src/lib.rs#L288-L291.With the additions in this PR it would be possible to update the creation of the
ScheduledThreadPool
to use one of these newOnDropBehavior
s, or at least allow users to specify their ownScheduledThreadPool
that uses one of these newOnDropBehaviour
s via thethread_pool
method on the builder.