@@ -287,7 +287,7 @@ func (l *streamListener) onStartPartitionRequest(
287287 select {
288288 case <- ctx .Done ():
289289 return ctx .Err ()
290- case <- event .confirm .DoneChan :
290+ case <- event .confirm .Done () :
291291 userResp , _ = event .confirm .Get ()
292292 }
293293
@@ -344,15 +344,15 @@ func (l *streamListener) onStopPartitionRequest(
344344 // remove partition on the confirmation or on the listener closed
345345 select {
346346 case <- l .background .Done ():
347- case <- event .confirm .DoneChan :
347+ case <- event .confirm .Done () :
348348 }
349349 _ , _ = l .sessions .Remove (m .PartitionSessionID )
350350 }()
351351
352352 select {
353353 case <- ctx .Done ():
354354 return ctx .Err ()
355- case <- event .confirm .DoneChan :
355+ case <- event .confirm .Done () :
356356 // pass
357357 }
358358
@@ -398,27 +398,37 @@ func (l *streamListener) sendMessage(m rawtopicreader.ClientMessage) {
398398}
399399
400400type confirmStorage [T any ] struct {
401- DoneChan empty.Chan
401+ doneChan empty.Chan
402402 confirmed atomic.Bool
403403 val T
404404 confirmAction sync.Once
405+ initAction sync.Once
405406}
406407
407- func newConfirmStorage [ T any ]() confirmStorage [T ] {
408- return confirmStorage [ T ] {
409- DoneChan : make (empty.Chan ),
410- }
408+ func ( c * confirmStorage [T ]) init () {
409+ c . initAction . Do ( func () {
410+ c . doneChan = make (empty.Chan )
411+ })
411412}
412413
413414func (c * confirmStorage [T ]) Set (val T ) {
415+ c .init ()
414416 c .confirmAction .Do (func () {
415417 c .val = val
416418 c .confirmed .Store (true )
417- close (c .DoneChan )
419+ close (c .doneChan )
418420 })
419421}
420422
423+ func (c * confirmStorage [T ]) Done () empty.ChanReadonly {
424+ c .init ()
425+
426+ return c .doneChan
427+ }
428+
421429func (c * confirmStorage [T ]) Get () (val T , ok bool ) {
430+ c .init ()
431+
422432 if c .confirmed .Load () {
423433 return c .val , true
424434 }
0 commit comments