Skip to content

Commit

Permalink
Merge pull request #1857 from c9s/kbearXD/depth/unlock-after-emit
Browse files Browse the repository at this point in the history
FEATURE: [max] unlock depth buffer after emit
  • Loading branch information
c9s authored Dec 11, 2024
2 parents c65fa40 + d13ae90 commit 46db54e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/depth/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (b *Buffer) SetUpdateTimeout(d time.Duration) {
}

func (b *Buffer) resetSnapshot() {
log.Info("resetting the snapshot")
b.snapshot = nil
b.finalUpdateID = 0
}
Expand Down Expand Up @@ -91,16 +92,16 @@ func (b *Buffer) SetSnapshot(snapshot types.SliceOrderBook, firstUpdateID int64,
return nil
}

log.Info("setting the snapshot")
// set the final update ID so that we will know if there is an update missing
b.finalUpdateID = finalUpdateID

// set the snapshot
b.snapshot = &snapshot
b.EmitReady(snapshot, nil)

b.mu.Unlock()

// should unlock first then call ready
b.EmitReady(snapshot, nil)
return nil
}

Expand Down Expand Up @@ -176,10 +177,10 @@ func (b *Buffer) AddUpdate(o types.SliceOrderBook, firstUpdateID int64, finalArg

log.Debugf("depth update id %d -> %d", b.finalUpdateID, u.FinalUpdateID)
b.finalUpdateID = u.FinalUpdateID
b.mu.Unlock()

b.EmitPush(u)

b.mu.Unlock()

return nil
}

Expand Down Expand Up @@ -243,10 +244,9 @@ func (b *Buffer) fetchAndPush() error {

// set the snapshot
b.snapshot = &book
b.EmitReady(book, pushUpdates)

b.mu.Unlock()

// should unlock first then call ready
b.EmitReady(book, pushUpdates)
return nil
}

0 comments on commit 46db54e

Please sign in to comment.