improvements at NewConn - now w opts, more flexible

master
Paulo Simão 2021-11-17 06:14:14 -03:00
parent 33db6dfaac
commit 6bd5a3a5ac
1 changed files with 60 additions and 54 deletions

View File

@ -22,8 +22,6 @@ func dbg(s string, p ...interface{}) {
type MQConn struct {
opts *MQConnOpts
retry bool
chRetry chan *struct{}
//chReady chan *struct{}
subs sync.Map
mtx sync.Mutex
@ -189,8 +187,7 @@ func (c *MQConn) Loop() {
}
func (c *MQConn) Init() error {
c.retry = true
if c.retry {
doConn := func() error {
d := websocket.Dialer{
NetDial: nil,
@ -244,9 +241,14 @@ func (c *MQConn) Init() error {
}
return true
})
}
return nil
}
func (c *MQConn) Close() error {
c.retry = false
return c.conn.Close()
}
type MQConnOpts struct {
Url string
@ -257,8 +259,12 @@ type MQConnOpts struct {
func New(o *MQConnOpts) (*MQConn, error) {
ret := &MQConn{
opts: o,
retry: true,
}
err := ret.Init()
if err != nil {
return nil, err
}
go func() {
for ret.retry {
ret.Loop()