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/advanced tick listener #36

Merged
merged 8 commits into from
Apr 17, 2024
Merged

Conversation

joshika39
Copy link
Member

@joshika39 joshika39 commented Apr 17, 2024

Closes #33

Summary by CodeRabbit

  • New Features

    • Enhanced stopwatch functionality to support named operations and improve tracking with unique identifiers.
    • Introduced ability to perform periodic operations with specific names and optional cancellation.
  • Refactor

    • Updated method signatures and internal handling to accommodate new named operations feature.
  • Tests

    • Added tests to ensure correct notification of listeners during named periodic operations.
  • Documentation

    • Expanded interface documentation to include new properties and method overloads related to named operations.

Copy link

coderabbitai bot commented Apr 17, 2024

Walkthrough

The recent updates involve enhancements to the stopwatch functionality in a software system, focusing on distinguishing between multiple stopwatches triggering events. Key changes include the addition of named operations and the ability to pass more detailed information during event triggers, specifically identifying the initiating stopwatch.

Changes

Files Changes
.../Time/DefaultStopwatch.cs
.../Time/PeriodicStopwatch.cs
Added name identification and modified method parameters to enhance event detail.
.../Time/IPeriodicStopwatch.cs
.../Time/IStopwatch.cs
Interface updates to support named operations and hierarchical relationships between stopwatches.
.../Time/Listeners/INamedStopwatch.cs
.../Time/Listeners/ITickListener.cs
New interfaces and methods to handle named events and detailed event information.
.../ImplementationTest/Time/DummyListener.cs
.../ImplementationTest/Time/StopwatchTests.cs
Test enhancements to validate new functionality and named event notifications.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Timer's RaiseTick can decide which timer initiated the tick (#33)

Poem

🐰 A CodeRabbit's Ode to Time 🕒
In the burrow of code, where the stopwatches lie,
Named and brave, they tick-tock as time flies.
Each tick a story, each name a song,
In the vast code meadows, where they belong.
Cheers to the clocks, with names so bright,
Guiding through code, from day to night. 🌟


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e4e9b76 and 9a5f9c1.
Files selected for processing (8)
  • _src/Implementation/Time/DefaultStopwatch.cs (4 hunks)
  • _src/Implementation/Time/PeriodicStopwatch.cs (3 hunks)
  • _src/Infrastructure/Time/IPeriodicStopwatch.cs (1 hunks)
  • _src/Infrastructure/Time/IStopwatch.cs (1 hunks)
  • _src/Infrastructure/Time/Listeners/INamedStopwatch.cs (1 hunks)
  • _src/Infrastructure/Time/Listeners/ITickListener.cs (1 hunks)
  • _src/_Tests/ImplementationTest/Time/DummyListener.cs (1 hunks)
  • _src/_Tests/ImplementationTest/Time/StopwatchTests.cs (1 hunks)
Additional comments not posted (6)
_src/Infrastructure/Time/Listeners/INamedStopwatch.cs (1)

3-6: The INamedStopwatch interface is correctly defined with a read-only Name property, adhering to good interface design practices.

_src/Infrastructure/Time/Listeners/ITickListener.cs (1)

8-8: The updated RaiseTick method in ITickListener interface now correctly includes parameters for the initiating stopwatch, its name, and the round, enhancing event detail and traceability.

_src/Infrastructure/Time/IPeriodicStopwatch.cs (1)

6-8: The enhancements to IPeriodicStopwatch interface, including inheriting from INamedStopwatch and adding a Parent property, are well-thought-out, improving the stopwatch's functionality and traceability.

_src/Infrastructure/Time/IStopwatch.cs (1)

18-22: The new method overloads in IStopwatch for named periodic operations enhance the interface's functionality by allowing for better identification and management of periodic tasks.

_src/_Tests/ImplementationTest/Time/StopwatchTests.cs (1)

52-68: The new test method ST_0021_Given_Stopwatch_When_WaitAsyncIsCalled_Then_ListenerGetsNotifiedWithNamedRaiseTick correctly verifies the functionality of named tick raises. Consider using more controlled timing mechanisms than Thread.Sleep for more reliable test outcomes.

_src/Implementation/Time/DefaultStopwatch.cs (1)

121-140: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [21-136]

The updates to the DefaultStopwatch class, including the addition of a unique name identifier, modifications to the Wait and WaitAsync methods, and new NamedPeriodicOperation method overloads, significantly enhance the class's functionality and flexibility.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@joshika39 joshika39 merged commit d0d94cf into master Apr 17, 2024
@joshika39 joshika39 deleted the feature/advanced-tick-listener branch April 17, 2024 22:30
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Comment on lines +22 to +25
public void RaiseTick(IStopwatch initiator, string name, int round)
{
Console.WriteLine($"{Name} -> {round}, time: {ElapsedTime}, initiator: {initiator}, name: {name}");
}
Copy link

Choose a reason for hiding this comment

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

The new RaiseTick method in DummyListener class correctly handles additional parameters for enhanced logging and tracing. Ensure to add unit tests to verify this new functionality.

Would you like me to help with writing these unit tests or should I open a GitHub issue to track this task?

Comment on lines +19 to +65
public bool IsRunning => Parent.IsRunning;
public IStopwatch Parent { get; }
public string Name { get; }
public TimeSpan Elapsed { get; private set; }

public PeriodicStopwatch(IStopwatch parent, int periodInMilliseconds, ITickListener listener, CancellationToken cancellationToken)
public PeriodicStopwatch(string name, IStopwatch parent, int periodInMilliseconds, ITickListener listener,
CancellationToken cancellationToken)
{
_parent = parent ?? throw new ArgumentNullException(nameof(parent));
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
_periodInMilliseconds = periodInMilliseconds;
_cancellationToken = cancellationToken;
_stopwatch = new Stopwatch();
_listeners = new List<ITickListener>();
_listeners.Add(listener);
Name = name;
}

public PeriodicStopwatch(string name, IStopwatch parent, int periodInMilliseconds, CancellationToken cancellationToken)
{
_periodInMilliseconds = periodInMilliseconds;
_cancellationToken = cancellationToken;
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
_stopwatch = new Stopwatch();
_listeners = new List<ITickListener>();
Name = name;
}

public PeriodicStopwatch(IStopwatch parent, int periodInMilliseconds, CancellationToken cancellationToken)
{
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
_periodInMilliseconds = periodInMilliseconds;
_cancellationToken = cancellationToken;
_stopwatch = new Stopwatch();
_listeners = new List<ITickListener>();
Name = Guid.NewGuid().ToString();
}

public PeriodicStopwatch(IStopwatch parent, int periodInMilliseconds, ITickListener listener,
CancellationToken cancellationToken)
{
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
_periodInMilliseconds = periodInMilliseconds;
_cancellationToken = cancellationToken;
_parent = parent ?? throw new ArgumentNullException(nameof(parent));
_stopwatch = new Stopwatch();
_listeners = new List<ITickListener>();
_listeners.Add(listener);
Name = Guid.NewGuid().ToString();
Copy link

Choose a reason for hiding this comment

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

The updates to the PeriodicStopwatch class, including the addition of Parent and Name properties and modifications to the constructors, enhance the class's functionality and maintainability. Ensure to add unit tests to verify the behavior of these new properties and constructors.

Would you like me to help with writing these unit tests or should I open a GitHub issue to track this task?

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.

timer's RaiseTick can decide which timer initiated the tick
1 participant