Skip to content

Commit

Permalink
Fix some crashes for atomic function references
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Dec 26, 2023
1 parent 27e97b1 commit e765d9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions internal/app/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,40 @@ func (l *Lifecycle) SetOnStopped(f func()) {

// TriggerEnteredForeground will call the focus gained hook, if one is registered.
func (l *Lifecycle) TriggerEnteredForeground() {
f := *l.onForeground.Load()
f := l.onForeground.Load()
if f == nil {
return
}

f()
(*f)()
}

// TriggerExitedForeground will call the focus lost hook, if one is registered.
func (l *Lifecycle) TriggerExitedForeground() {
f := *l.onBackground.Load()
f := l.onBackground.Load()
if f == nil {
return
}

f()
(*f)()
}

// TriggerStarted will call the started hook, if one is registered.
func (l *Lifecycle) TriggerStarted() {
f := *l.onStarted.Load()
f := l.onStarted.Load()
if f == nil {
return
}

f()
(*f)()
}

// TriggerStopped will call the stopped hook, if one is registered,
// and an internal stopped hook after that.
func (l *Lifecycle) TriggerStopped() {
f := *l.onStopped.Load()
f := l.onStopped.Load()
if f != nil {
f()
(*f)()
}

if l.onStoppedHookExecuted != nil {
Expand Down
4 changes: 2 additions & 2 deletions widget/bind_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type basicBinder struct {
// Bind replaces the data item whose changes are tracked by the callback function.
func (binder *basicBinder) Bind(data binding.DataItem) {
listener := binding.NewDataListener(func() { // NB: listener captures `data` but always calls the up-to-date callback
f := *binder.callback.Load()
f := binder.callback.Load()
if f == nil {
return
}

f(data)
(*f)(data)
})
data.AddListener(listener)
listenerInfo := annotatedListener{
Expand Down

0 comments on commit e765d9a

Please sign in to comment.