-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tokio-util: time: add DelayQueue::peek
#5569
Conversation
The test failure isn't your fault. See #5570. |
However, there's a test failure now, which appears to be in your code. |
Not quite sure why, this code shouldn't behave differently on Windows. Do you have any idea why that might be? Worst case I can try increasing the durations used. |
The proper fix would be to use |
I found the issue with the original test, the entry inserted at |
So the behavior is different for timers that have already expired? Can you please elaborate on this in the documentation? |
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
I've updated the documentation to reflect this |
Honestly, the behavior for expired timers worries me a bit. It would be quite surprising if you don't closely read the docs. Can we not fix it? |
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
Sure thing! I've restored the original test and it now considers entries marked as expired first. |
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.
Please add a test that it always returns the earliest key, even when there are multiple expired keys, no matter the order they were inserted in.
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
|
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
DelayQueue::next_expiring
DelayQueue::peek
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
I've renamed the method to |
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
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.
Thanks.
Motivation
My goal is to implement an expiring LRU cache that uses a
DashMap
+DelayQueue
with an optional maximum capacity. On capacity overflow, I want to remove the item that would've been next to expire. I described this issue in #5279.Solution
Adding
DelayQueue::peek
allows for getting theKey
that will expire next. In my usecase, aDelayQueue<K>
+DashMap<K, V>
is used, so after removing the next expiring key from the queue, it can also be used to remove it from the map becauseK
is now known. I made an implementation that showcases this here.This implementation is based on
pop_entry_slot
and usespeek
methods instead which don't touch the contents of the stack and levels.Closes: #5279