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

Feature: Add TypeConfigExt to simplify RaftTypeConfig Access #1145

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Jul 3, 2024

Changelog

Feature: Add TypeConfigExt to simplify RaftTypeConfig Access

This commit introduces a new trait, TypeConfigExt, which extends
RaftTypeConfig. The purpose of this trait is to simplify the access to
various functionalities provided by the RaftTypeConfig trait,
enhancing code readability and reducing complexity.

Methods Added to TypeConfigExt:

  • now()
  • sleep()
  • sleep_until()
  • timeout()
  • timeout_at()
  • oneshot()
  • spawn()

Usage Improvement:

  • Instead of using the
    <<C as RaftTypeConfig>::AsyncRuntime as AsyncRuntime>::Instant::now(),
    you can now simply call C::now().

This change is Reviewable

@drmingdrmer drmingdrmer force-pushed the 83-type-ext branch 2 times, most recently from 29a8aab to 7219828 Compare July 3, 2024 14:28
@drmingdrmer drmingdrmer requested a review from schreter July 3, 2024 14:28
schreter
schreter previously approved these changes Jul 3, 2024
Copy link
Collaborator

@schreter schreter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Reviewed 17 of 17 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @drmingdrmer)


openraft/src/type_config/util.rs line 20 at r1 (raw file):

    // Time related methods

    /// Returns the current time

Suggestion:

    /// Returns the current time.

openraft/src/type_config/util.rs line 50 at r1 (raw file):

    // Synchronization methods

    fn oneshot<T>() -> (OneshotSenderOf<Self, T>, OneshotReceiverOf<Self, T>)

Maybe add docs to the method?

This commit introduces a new trait, `TypeConfigExt`, which extends
`RaftTypeConfig`. The purpose of this trait is to simplify the access to
various functionalities provided by the `RaftTypeConfig` trait,
enhancing code readability and reducing complexity.

**Methods Added to `TypeConfigExt`:**
- `now()`
- `sleep()`
- `sleep_until()`
- `timeout()`
- `timeout_at()`
- `oneshot()`
- `spawn()`

**Usage Improvement:**
- Instead of using the
  `<<C as RaftTypeConfig>::AsyncRuntime as AsyncRuntime>::Instant::now()`,
  you can now simply call `C::now()`.
@drmingdrmer drmingdrmer merged commit c71a95d into databendlabs:main Jul 4, 2024
30 of 31 checks passed
@drmingdrmer drmingdrmer deleted the 83-type-ext branch July 4, 2024 07:52
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