mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
types: split pendingRemoval lock scope
This commit is contained in:
parent
fc7edc5c80
commit
77e31e9274
|
@ -125,26 +125,34 @@ func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
|
||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SyncOrderMap) Add(o Order) {
|
func (m *SyncOrderMap) processPendingRemoval() {
|
||||||
|
if len(m.pendingRemoval) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
m.orders.Add(o)
|
expireTime := time.Now().Add(-5 * time.Minute)
|
||||||
|
removing := make(map[uint64]struct{})
|
||||||
if len(m.pendingRemoval) > 0 {
|
for orderID, creationTime := range m.pendingRemoval {
|
||||||
expireTime := time.Now().Add(-5 * time.Minute)
|
if m.orders.Exists(orderID) || creationTime.Before(expireTime) {
|
||||||
removing := make(map[uint64]struct{})
|
m.orders.Remove(orderID)
|
||||||
for orderID, creationTime := range m.pendingRemoval {
|
removing[orderID] = struct{}{}
|
||||||
if m.orders.Exists(orderID) || creationTime.Before(expireTime) {
|
|
||||||
m.orders.Remove(orderID)
|
|
||||||
removing[orderID] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for orderID := range removing {
|
|
||||||
delete(m.pendingRemoval, orderID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for orderID := range removing {
|
||||||
|
delete(m.pendingRemoval, orderID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SyncOrderMap) Add(o Order) {
|
||||||
|
m.Lock()
|
||||||
|
m.orders.Add(o)
|
||||||
|
m.Unlock()
|
||||||
|
|
||||||
|
m.processPendingRemoval()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SyncOrderMap) Update(o Order) {
|
func (m *SyncOrderMap) Update(o Order) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user