-
Notifications
You must be signed in to change notification settings - Fork 5
WatchedSetting based refresh #14
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
linglingye001
merged 12 commits into
release/v1.0.0-beta.2
from
linglingye/sentinelBasedRefresh
Apr 24, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
df28774
resolve conflict
linglingye001 0f29f3f
add tests
linglingye001 408aa12
fix typo
linglingye001 cc5178a
update
linglingye001 402edf5
rebase
linglingye001 76bb184
update
linglingye001 80a3286
update
linglingye001 57bdb0c
update
linglingye001 c733192
update
linglingye001 3b800c8
update
linglingye001 b886cc9
update
linglingye001 6e83dbd
update
linglingye001 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package refresh | ||
|
|
||
| import "time" | ||
|
|
||
| // Timer manages the timing for refresh operations | ||
| type Timer struct { | ||
| interval time.Duration // How often refreshes should occur | ||
| nextRefreshTime time.Time // When the next refresh should occur | ||
| } | ||
|
|
||
| // Condition interface defines the methods a refresh timer should implement | ||
| type Condition interface { | ||
| ShouldRefresh() bool | ||
| Reset() | ||
| } | ||
|
|
||
| const ( | ||
| DefaultRefreshInterval time.Duration = 30 * time.Second | ||
| ) | ||
|
|
||
| // NewTimer creates a new refresh timer with the specified interval | ||
| // If interval is zero or negative, it falls back to the DefaultRefreshInterval | ||
| func NewTimer(interval time.Duration) *Timer { | ||
| // Use default interval if not specified or invalid | ||
| if interval <= 0 { | ||
| interval = DefaultRefreshInterval | ||
| } | ||
|
|
||
| return &Timer{ | ||
| interval: interval, | ||
| nextRefreshTime: time.Now().Add(interval), | ||
| } | ||
| } | ||
|
|
||
| // ShouldRefresh checks whether it's time for a refresh | ||
| func (rt *Timer) ShouldRefresh() bool { | ||
| return !time.Now().Before(rt.nextRefreshTime) | ||
| } | ||
|
|
||
| // Reset resets the timer for the next refresh cycle | ||
| func (rt *Timer) Reset() { | ||
| rt.nextRefreshTime = time.Now().Add(rt.interval) | ||
| } |
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.
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.