mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-10-04 07:06:25 +08:00
Split k.NewChatHandlerOBSOLETE
This commit is contained in:
@@ -64,19 +64,24 @@ func NewChatHandlerOBSOLETE(
|
||||
client: chatClient,
|
||||
channelID: channelID,
|
||||
cancelFunc: cancelFn,
|
||||
messagesOutChan: make(chan streamcontrol.ChatMessage, 100),
|
||||
onClose: onClose,
|
||||
}
|
||||
h.init(ctx)
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (h *ChatHandlerOBSOLETE) init(ctx context.Context) {
|
||||
h.messagesOutChan = make(chan streamcontrol.ChatMessage, 100)
|
||||
observability.Go(ctx, func(ctx context.Context) {
|
||||
if onClose != nil {
|
||||
defer func() {
|
||||
onClose(ctx, h)
|
||||
}()
|
||||
if h.onClose != nil {
|
||||
defer h.onClose(ctx, h)
|
||||
}
|
||||
defer func() {
|
||||
close(h.messagesOutChan)
|
||||
}()
|
||||
defer close(h.messagesOutChan)
|
||||
h.loop(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func (h *ChatHandlerOBSOLETE) loop(ctx context.Context) {
|
||||
err := h.iterate(ctx)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "unable to perform an iteration: %v", err)
|
||||
@@ -97,9 +102,6 @@ func NewChatHandlerOBSOLETE(
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (h *ChatHandlerOBSOLETE) iterate(ctx context.Context) error {
|
||||
|
Reference in New Issue
Block a user