mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-29 18:34:04 +08:00
Merge 30b7814aaf4ce23e598e5cdf663feb0655975ef5 into d16a617ba8ff690cb668558bb2e597b4f3cbecf6
This commit is contained in:
commit
4f12482255
@ -151,12 +151,21 @@ func (b *Batcher[T]) Put(ctx context.Context, data *T) error {
|
|||||||
|
|
||||||
func (b *Batcher[T]) scheduler() {
|
func (b *Batcher[T]) scheduler() {
|
||||||
ticker := time.NewTicker(b.config.interval)
|
ticker := time.NewTicker(b.config.interval)
|
||||||
|
// Track whether b.data was closed by an external caller so the
|
||||||
|
// cleanup below does not close it a second time. The only routes
|
||||||
|
// out of this function that leave b.data open are the nil-message
|
||||||
|
// and ticker paths; the ok == false branch means someone already
|
||||||
|
// closed the channel, and calling close(b.data) again there would
|
||||||
|
// panic with "close of closed channel" (#3653).
|
||||||
|
externallyClosed := false
|
||||||
defer func() {
|
defer func() {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
for _, ch := range b.chArrays {
|
for _, ch := range b.chArrays {
|
||||||
close(ch)
|
close(ch)
|
||||||
}
|
}
|
||||||
close(b.data)
|
if !externallyClosed {
|
||||||
|
close(b.data)
|
||||||
|
}
|
||||||
b.wait.Done()
|
b.wait.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -169,6 +178,7 @@ func (b *Batcher[T]) scheduler() {
|
|||||||
case data, ok := <-b.data:
|
case data, ok := <-b.data:
|
||||||
if !ok {
|
if !ok {
|
||||||
// If the data channel is closed unexpectedly
|
// If the data channel is closed unexpectedly
|
||||||
|
externallyClosed = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if data == nil {
|
if data == nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user