Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Consider adding a Duration enum with INFINITE and INSTANTANEOUS #93

Open

Description

@llucax

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)

Activity

  1. added
    part:client
    scope:breaking-change
    type:enhancement
    on Sep 25, 2024
  2. llucax commented on Oct 25, 2024

    @llucax
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    part:clientpart:dispatcherscope:breaking-changetype:enhancement

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions