events/broadcaster Buffer val when writing to subscriber channel

Signed-off-by: joshvanl <me@joshvanl.dev>
This commit is contained in:
joshvanl 2025-01-07 09:34:35 +00:00
parent 65ba3783f2
commit 9b686e7493
1 changed files with 8 additions and 1 deletions

View File

@ -91,7 +91,14 @@ func (b *Broadcaster[T]) subscribe(ctx context.Context, ch chan<- T) {
return
case <-b.closeCh:
return
case ch <- <-bufferedCh:
case val := <-bufferedCh:
select {
case <-ctx.Done():
return
case <-b.closeCh:
return
case ch <- val:
}
}
}
}()