Skip to content

Commit

Permalink
Naming
Browse files Browse the repository at this point in the history
  • Loading branch information
c032 committed Feb 10, 2024
1 parent a0de329 commit 8df6049
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ type Notifier interface {
//
// It returns a function that, when called, should un-register `callback`
// so that it's no longer called on updates.
OnUpdate(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc
OnUpdate(callback NotifierCallbackFunc) RemoveCallbackFunc
}

type OnUpdateCallbackFunc func()
type RemoveOnUpdateCallbackFunc func()
type NotifierCallbackFunc func()
type RemoveCallbackFunc func()

type NotifierFunc func(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc
// UpdateNotifier is a wrapper for a function with the same signature as
// `Notifier.OnUpdate`, that implements `Notifier` by using itself as the
// `OnUpdate` method.
type UpdateNotifier func(callback NotifierCallbackFunc) RemoveCallbackFunc

func (fn NotifierFunc) OnUpdate(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc {
func (fn UpdateNotifier) OnUpdate(callback NotifierCallbackFunc) RemoveCallbackFunc {
return fn(callback)
}
2 changes: 1 addition & 1 deletion statuslineblockprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type StatusLineBlockProvider func(ctx context.Context, ch chan<- StatusLineBlock
func slbpToNotifier(ctx context.Context, p StatusLineBlockProvider) (Notifier, *atomic.Pointer[StatusLineBlock]) {
statusProvider := &atomic.Pointer[StatusLineBlock]{}

source := NotifierFunc(func(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc {
source := UpdateNotifier(func(callback NotifierCallbackFunc) RemoveCallbackFunc {
ch := make(chan StatusLineBlock)

ctxProvider, cancel := context.WithCancelCause(ctx)
Expand Down
4 changes: 2 additions & 2 deletions time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (tn *Notifier) runCallbacks() {

// We want this to panic if the conversion can't be done, because that
// would mean there's a bug somewhere.
callback := value.(dsts.OnUpdateCallbackFunc)
callback := value.(dsts.NotifierCallbackFunc)

callback()

Expand Down Expand Up @@ -92,7 +92,7 @@ func (tn *Notifier) init() {
}
}

func (tn *Notifier) OnUpdate(callback dsts.OnUpdateCallbackFunc) dsts.RemoveOnUpdateCallbackFunc {
func (tn *Notifier) OnUpdate(callback dsts.NotifierCallbackFunc) dsts.RemoveCallbackFunc {
tn.Lock()
defer tn.Unlock()

Expand Down

0 comments on commit 8df6049

Please sign in to comment.