Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
Signed-off-by: zyguan <[email protected]>
  • Loading branch information
zyguan committed Feb 22, 2024
1 parent cf6ddc3 commit 9765a4f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/locate/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,15 @@ func (mu *regionIndexMu) refresh(r []*Region) {

type livenessFunc func(ctx context.Context, s *Store) livenessState

// repeat wraps a `func()` as a schedulable fuction for `bgRunner`.
func repeat(f func()) func(context.Context, time.Time) bool {
return func(_ context.Context, _ time.Time) bool {
f()
return false
}
}

// until wraps a `func() bool` as a schedulable fuction for `bgRunner`.
func until(f func() bool) func(context.Context, time.Time) bool {
return func(_ context.Context, _ time.Time) bool {
return f()
Expand Down Expand Up @@ -551,6 +553,7 @@ func (r *bgRunner) shutdown(wait bool) {
}
}

// run calls `f` once in background.
func (r *bgRunner) run(f func(context.Context)) {
if r.closed() {
return
Expand All @@ -562,6 +565,7 @@ func (r *bgRunner) run(f func(context.Context)) {
}()
}

// schedule calls `f` every `interval`.
func (r *bgRunner) schedule(f func(context.Context, time.Time) bool, interval time.Duration) {
if r.closed() {
return
Expand All @@ -586,6 +590,7 @@ func (r *bgRunner) schedule(f func(context.Context, time.Time) bool, interval ti
}()
}

// scheduleWithTrigger likes schedule, but also call `f` when `<-trigger`, in which case the time arg of `f` is zero.
func (r *bgRunner) scheduleWithTrigger(f func(context.Context, time.Time) bool, interval time.Duration, trigger <-chan struct{}) {
if r.closed() {
return
Expand Down

0 comments on commit 9765a4f

Please sign in to comment.