Skip to content
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

Consider adding a Duration enum with INFINITE and INSTANTANEOUS #93

Open
llucax opened this issue Sep 25, 2024 · 1 comment
Open

Consider adding a Duration enum with INFINITE and INSTANTANEOUS #93

llucax opened this issue Sep 25, 2024 · 1 comment
Labels
part:client Affects the client code part:dispatcher scope:breaking-change Breaking change, users will need to update their code type:enhancement New feature or enhancement visitble to users

Comments

@llucax
Copy link
Contributor

llucax commented Sep 25, 2024

We could use special values to represent INFINITE and INSTANTANEOUS for the Dispatch.duration field, so the code gets more readable (without the need for comments) and more type-safe.

We could set the type of duration: timedelta | Duration where duration is a enum for example, then we can also use match like this:

match dispatch.duration:
    case Duration.INFINITE: ...
    case Duration.INSTANTANEOUS: ...
    case timedelta(): ... (here we know it is > 0)
    case unexpected: assert_never(unexpected)

Taking it even a bit further, we could have a PositiveTimedelta object that even guarantee the time is positive.

Originally posted by @llucax in frequenz-floss/frequenz-dispatch-python#54 (comment)

@llucax llucax added part:client Affects the client code part:dispatcher scope:breaking-change Breaking change, users will need to update their code type:enhancement New feature or enhancement visitble to users labels Sep 25, 2024
@llucax
Copy link
Contributor Author

llucax commented Oct 25, 2024

This came up again, as there seems to be easy to get confused by the different meaning of duration based on if it is 0 or None, so it might be a good idea to prioritize it @Marenz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:client Affects the client code part:dispatcher scope:breaking-change Breaking change, users will need to update their code type:enhancement New feature or enhancement visitble to users
Projects
None yet
Development

No branches or pull requests

1 participant