1、暂存
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go-admin/models"
|
||||
@ -19,6 +20,7 @@ type BinanceWs struct {
|
||||
proxyUrl string
|
||||
WorkType string
|
||||
wsConns []*WsConn
|
||||
mu sync.Mutex // 新增互斥锁
|
||||
tickerCallback func(models.Ticker24, string, string)
|
||||
forceCallback func(models.ForceOrder, string, string)
|
||||
depthCallback func(models.DepthBin, string, string)
|
||||
@ -70,11 +72,15 @@ func (bnWs *BinanceWs) subscribe(endpoint string, handle func(msg []byte) error)
|
||||
if wsConn == nil {
|
||||
return
|
||||
}
|
||||
bnWs.mu.Lock()
|
||||
bnWs.wsConns = append(bnWs.wsConns, wsConn)
|
||||
bnWs.mu.Unlock()
|
||||
go bnWs.exitHandler(wsConn)
|
||||
}
|
||||
|
||||
func (bnWs *BinanceWs) Close() {
|
||||
bnWs.mu.Lock()
|
||||
defer bnWs.mu.Unlock()
|
||||
for _, con := range bnWs.wsConns {
|
||||
con.CloseWs()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user