mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
types: split pendingRemoval lock scope
This commit is contained in:
parent
fc7edc5c80
commit
77e31e9274
|
@ -125,13 +125,14 @@ 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)
|
|
||||||
|
|
||||||
if len(m.pendingRemoval) > 0 {
|
|
||||||
expireTime := time.Now().Add(-5 * time.Minute)
|
expireTime := time.Now().Add(-5 * time.Minute)
|
||||||
removing := make(map[uint64]struct{})
|
removing := make(map[uint64]struct{})
|
||||||
for orderID, creationTime := range m.pendingRemoval {
|
for orderID, creationTime := range m.pendingRemoval {
|
||||||
|
@ -144,7 +145,14 @@ func (m *SyncOrderMap) Add(o Order) {
|
||||||
for orderID := range removing {
|
for orderID := range removing {
|
||||||
delete(m.pendingRemoval, orderID)
|
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