From 805fea32df9150e8496346d748c17aa23cb8d125 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 24 Jan 2024 17:48:13 +0800 Subject: [PATCH] types: avoid using defer unlock in CopyDepth --- pkg/types/orderbook.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/types/orderbook.go b/pkg/types/orderbook.go index 6fbc92ba9..39bd4e5d0 100644 --- a/pkg/types/orderbook.go +++ b/pkg/types/orderbook.go @@ -101,25 +101,25 @@ func (b *MutexOrderBook) Reset() { b.Unlock() } -func (b *MutexOrderBook) CopyDepth(depth int) OrderBook { +func (b *MutexOrderBook) CopyDepth(depth int) (ob OrderBook) { b.Lock() - defer b.Unlock() - - return b.orderBook.CopyDepth(depth) + ob = b.orderBook.CopyDepth(depth) + b.Unlock() + return ob } -func (b *MutexOrderBook) Copy() OrderBook { +func (b *MutexOrderBook) Copy() (ob OrderBook) { b.Lock() - defer b.Unlock() + ob = b.orderBook.Copy() + b.Unlock() - return b.orderBook.Copy() + return ob } func (b *MutexOrderBook) Update(update SliceOrderBook) { b.Lock() - defer b.Unlock() - b.orderBook.Update(update) + b.Unlock() } type BookSignalType string