1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-10 01:51:11 +09:00

WIP queue metrics

This commit is contained in:
mcrakhman 2024-06-24 21:29:16 +02:00
parent 88c12436a6
commit f37064e0d7
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
31 changed files with 307 additions and 57 deletions

View file

@ -8,7 +8,7 @@ import (
type RequestPool interface {
TryTake(peerId, objectId string) bool
Release(peerId, objectId string)
QueueRequestAction(peerId, objectId string, action func(ctx context.Context)) (err error)
QueueRequestAction(peerId, objectId string, action func(ctx context.Context), remove func()) (err error)
Close()
}
@ -45,7 +45,7 @@ func (rp *requestPool) Release(peerId, objectId string) {
rp.peerGuard.Release(fullId(peerId, objectId))
}
func (rp *requestPool) QueueRequestAction(peerId, objectId string, action func(ctx context.Context)) (err error) {
func (rp *requestPool) QueueRequestAction(peerId, objectId string, action func(ctx context.Context), remove func()) (err error) {
rp.mu.Lock()
if rp.isClosed {
rp.mu.Unlock()
@ -65,13 +65,12 @@ func (rp *requestPool) QueueRequestAction(peerId, objectId string, action func(c
var wrappedAction func()
wrappedAction = func() {
if !rp.TryTake(peerId, objectId) {
pool.TryAdd(objectId, wrappedAction, func() {})
return
}
action(rp.ctx)
rp.Release(peerId, objectId)
}
pool.Replace(objectId, wrappedAction, func() {})
pool.Replace(objectId, wrappedAction, remove)
return nil
}