-
Notifications
You must be signed in to change notification settings - Fork 9
Support clearing the latest value in the LatestValueCache
#426
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,22 @@ def has_value(self, key: HashableT | Sentinel = NO_KEY) -> bool: | |
| return key in self._latest_value_by_key | ||
| return not isinstance(self._latest_value, Sentinel) | ||
|
|
||
| def clear(self, key: HashableT | Sentinel = NO_KEY) -> None: | ||
| """Clear the latest value or the latest value for a specific key. | ||
|
|
||
| If `key` is provided, it clears the latest value for that key. If no key is | ||
| provided, it clears the latest value received overall. | ||
|
|
||
| Args: | ||
| key: An optional key to clear the latest value for that key. If not | ||
| provided, it clears the latest value received overall. | ||
| """ | ||
| if not isinstance(key, Sentinel): | ||
| _ = self._latest_value_by_key.pop(key, None) | ||
| return | ||
|
|
||
| self._latest_value = NO_VALUE_RECEIVED | ||
|
|
||
|
Comment on lines
+197
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh damn, because my usecase didn't need clearing all keys. I wonder if we should change the API slightly to keep the option open for a "clear everything" in the future. any opinions @llucax ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option is to make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some options I can think of:
I'm starting to find the use case for a "global" key a bit weird. I guess we need to support it for backwards compatibility, otherwise maybe we should always require a key and let the user use something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We haven't released it. I can actually pull out all the new stuff into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done here: #428 |
||
| async def _run(self) -> None: | ||
| async for value in self._receiver: | ||
| self._latest_value = value | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.