Skip to content

Conversation

@xldenis
Copy link

@xldenis xldenis commented Sep 8, 2025

This PR implements a solution to #73, introducing a get_validate_or_guard_async method which allows passing a validation function to determine whether we should consider the currently inserted value as 'live'. If the value fails validation it will be replaced with a Placeholder and the guard returned.

todo:

  • tests
  • unsync versions
  • non-async apis
  • bench to confirm no perf regression (shouldn't be the case).

@xldenis
Copy link
Author

xldenis commented Sep 10, 2025

I've been thinking about the semantics of this, and I think there's footgun in it currently. If multiple tasks call this api with different validation functions there's no guarantee that when you resume you have a value that will satisfy your validation function. This feels like it could easily lead to bugs, the only fix I can think of is that one of the waked tasks should get a placeholder and try inserting a new value.

@arthurprs
Copy link
Owner

arthurprs commented Sep 13, 2025

Your concern makes sense. Hand-wavely, another option may be to hide the generic guard from the validation callers (e.g. GuardWithValidation), and write it in a way that it always tries to validate the value returned and loops/errors otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants