1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 14:07:02 +09:00

Merge pull request #152 from anyproto/go-1293-fix-ocache

GO-1293 Remove ocache goroutine
This commit is contained in:
Mikhail 2024-01-26 15:24:04 +03:00 committed by GitHub
commit a382f91434
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View file

@ -6,8 +6,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/anyproto/any-sync/app/logger"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/anyproto/any-sync/app/logger"
) )
var ( var (
@ -137,10 +138,11 @@ Load:
if reload { if reload {
goto Load goto Load
} }
if load {
go c.load(ctx, id, e)
}
c.metricsGet(!load) c.metricsGet(!load)
if load {
c.load(ctx, id, e)
return e.value, e.loadErr
}
return e.waitLoad(ctx, id) return e.waitLoad(ctx, id)
} }

View file

@ -126,6 +126,9 @@ func TestOCache_Get(t *testing.T) {
t.Run("context cancel", func(t *testing.T) { t.Run("context cancel", func(t *testing.T) {
c := New(func(ctx context.Context, id string) (value Object, err error) { c := New(func(ctx context.Context, id string) (value Object, err error) {
time.Sleep(time.Second / 3) time.Sleep(time.Second / 3)
if ctx.Err() != nil {
return nil, ctx.Err()
}
return &testObject{ return &testObject{
name: "id", name: "id",
}, nil }, nil