diff --git a/notifier.go b/notifier.go index 4e30a9b..46c0dd5 100644 --- a/notifier.go +++ b/notifier.go @@ -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) } diff --git a/statuslineblockprovider.go b/statuslineblockprovider.go index 2bba1ff..18b462e 100644 --- a/statuslineblockprovider.go +++ b/statuslineblockprovider.go @@ -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) diff --git a/time/time.go b/time/time.go index 6657547..e9fa9d3 100644 --- a/time/time.go +++ b/time/time.go @@ -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() @@ -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()