Skip to content

Commit

Permalink
fix: channel close once
Browse files Browse the repository at this point in the history
  • Loading branch information
strahe committed Dec 11, 2024
1 parent 42a7b02 commit 2c8c3e1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ const (
)

type watchMessage struct {
id uint
db *gorm.DB
started time.Time
cancelCh chan struct{}
id uint
db *gorm.DB
started time.Time
cancelOnce sync.Once
cancelCh chan struct{}
}

func newWatchMessage(db *gorm.DB, id uint) *watchMessage {
Expand All @@ -59,7 +60,9 @@ func newWatchMessage(db *gorm.DB, id uint) *watchMessage {
}

func (w *watchMessage) Cancel() {
close(w.cancelCh)
w.cancelOnce.Do(func() {
close(w.cancelCh)
})
}

func (w *watchMessage) Wait() {
Expand Down

0 comments on commit 2c8c3e1

Please sign in to comment.