-
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add support for PeriodicTimer in abstractions
#961
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Source/Testably.Abstractions.Interface/TimeSystem/IPeriodicTimer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #if FEATURE_PERIODIC_TIMER | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Testably.Abstractions.TimeSystem; | ||
|
|
||
| /// <summary> | ||
| /// Abstractions for <see cref="PeriodicTimer" />. | ||
| /// </summary> | ||
| public interface IPeriodicTimer : ITimeSystemEntity, IDisposable | ||
| { | ||
| /// <inheritdoc cref="PeriodicTimer.Period" /> | ||
| TimeSpan Period { get; set; } | ||
|
|
||
| /// <inheritdoc cref="PeriodicTimer.WaitForNextTickAsync(CancellationToken)" /> | ||
| ValueTask<bool> WaitForNextTickAsync(CancellationToken cancellationToken = default); | ||
| } | ||
| #endif |
20 changes: 20 additions & 0 deletions
20
Source/Testably.Abstractions.Interface/TimeSystem/IPeriodicTimerFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #if FEATURE_PERIODIC_TIMER | ||
| using System; | ||
| using System.Threading; | ||
|
|
||
| namespace Testably.Abstractions.TimeSystem; | ||
|
|
||
| /// <summary> | ||
| /// Factory for abstracting creation of <see cref="PeriodicTimer" />. | ||
| /// </summary> | ||
| public interface IPeriodicTimerFactory : ITimeSystemEntity | ||
| { | ||
| /// <inheritdoc cref="PeriodicTimer(TimeSpan)" /> | ||
| IPeriodicTimer New(TimeSpan period); | ||
|
|
||
| /// <summary> | ||
| /// Wraps the <paramref name="timer" /> to the testable <see cref="IPeriodicTimer" />. | ||
| /// </summary> | ||
| IPeriodicTimer Wrap(PeriodicTimer timer); | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Source/Testably.Abstractions/TimeSystem/PeriodicTimerFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #if FEATURE_PERIODIC_TIMER | ||
| using System; | ||
| using System.Threading; | ||
|
|
||
| namespace Testably.Abstractions.TimeSystem; | ||
|
|
||
| internal sealed class PeriodicTimerFactory : IPeriodicTimerFactory | ||
| { | ||
| internal PeriodicTimerFactory(RealTimeSystem timeSystem) | ||
| { | ||
| TimeSystem = timeSystem; | ||
| } | ||
|
|
||
| #region IPeriodicTimerFactory Members | ||
|
|
||
| /// <inheritdoc cref="ITimeSystemEntity.TimeSystem" /> | ||
| public ITimeSystem TimeSystem { get; } | ||
|
|
||
| /// <inheritdoc cref="IPeriodicTimerFactory.New(TimeSpan)" /> | ||
| public IPeriodicTimer New(TimeSpan period) | ||
| => Wrap(new PeriodicTimer(period)); | ||
|
|
||
| /// <inheritdoc cref="IPeriodicTimerFactory.Wrap(PeriodicTimer)" /> | ||
| public IPeriodicTimer Wrap(PeriodicTimer timer) | ||
| => new PeriodicTimerWrapper(TimeSystem, timer); | ||
|
|
||
| #endregion | ||
| } | ||
| #endif |
40 changes: 40 additions & 0 deletions
40
Source/Testably.Abstractions/TimeSystem/PeriodicTimerWrapper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #if FEATURE_PERIODIC_TIMER | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Testably.Abstractions.TimeSystem; | ||
|
|
||
| internal sealed class PeriodicTimerWrapper : IPeriodicTimer | ||
| { | ||
| private readonly PeriodicTimer _periodicTimer; | ||
|
|
||
| internal PeriodicTimerWrapper(ITimeSystem timeSystem, PeriodicTimer periodicTimer) | ||
| { | ||
| TimeSystem = timeSystem; | ||
| _periodicTimer = periodicTimer; | ||
| } | ||
|
|
||
| #region IPeriodicTimer Members | ||
|
|
||
| /// <inheritdoc cref="IPeriodicTimer.Period" /> | ||
| public TimeSpan Period | ||
| { | ||
| get => _periodicTimer.Period; | ||
| set => _periodicTimer.Period = value; | ||
| } | ||
|
|
||
| /// <inheritdoc cref="ITimeSystemEntity.TimeSystem" /> | ||
| public ITimeSystem TimeSystem { get; } | ||
|
|
||
| /// <inheritdoc cref="IDisposable.Dispose()" /> | ||
| public void Dispose() | ||
| => _periodicTimer.Dispose(); | ||
|
|
||
| /// <inheritdoc cref="IPeriodicTimer.WaitForNextTickAsync(CancellationToken)" /> | ||
| public ValueTask<bool> WaitForNextTickAsync(CancellationToken cancellationToken = default) | ||
| => _periodicTimer.WaitForNextTickAsync(cancellationToken); | ||
|
|
||
| #endregion | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.