DelayQueue::try_remove #3558
Labels
A-tokio-util
Area: The tokio-util crate
C-feature-request
Category: A feature request.
M-time
Module: tokio/time
Is your feature request related to a problem? Please describe.
DelayQueue::remove
states:There is no corresponding
Option
orResult
-returning method.This means that the user has to manually ensure they don't
remove
a key twice, or a key that has already been yielded bypoll_expired
.Describe the solution you'd like
Perhaps it would be okay to have a method that returns
None
instead of panicking, so thatKey
s can be passed around less carefully, but without overhead such as keeping aHashSet
of currently pendingKey
s alongside theDelayQueue
.Describe alternatives you've considered
Another option would be replacing
Key
withT: <some traits>
, so that the user can manually avoid collisions with semantic unique timer identifiers instead of moving literally anything into theDelayQueue
but having to use the opaque non-reusableKey
type.Additional context
The
Key
type just wraps ausize
, so a colliding key from another instance ofDelayQueue
or just an extremely old one could exist, causing a false positive removal. Perhaps the soft-failing methods were intentionally foregone to discourage membership checking.The text was updated successfully, but these errors were encountered: