reconnect timer + fixes

This commit is contained in:
nquidox 2026-02-21 15:03:43 +03:00
parent 13ee3230e3
commit 42646a6a08
3 changed files with 71 additions and 21 deletions

View file

@ -2,18 +2,34 @@ package rabbit
import (
"errors"
"log"
"time"
)
type Publisher interface {
Push(data []byte) error
Start(chanLen uint) <-chan []byte
}
type pubHandler struct {
client *Client
}
func (p *pubHandler) Push(data []byte) error {
func (p *pubHandler) Start(chanLen uint) <-chan []byte {
ch := make(chan []byte, chanLen)
go func() {
for {
select {
case msg := <-ch:
if err := p.push(msg); err != nil {
log.Printf("Error publishing message: %s", err)
}
}
}
}()
return ch
}
func (p *pubHandler) push(data []byte) error {
p.client.mutex.Lock()
if !p.client.isReady {
p.client.mutex.Unlock()