diff --git a/app/ocache/ocache.go b/app/ocache/ocache.go index c3bc9a0a..c91b3905 100644 --- a/app/ocache/ocache.go +++ b/app/ocache/ocache.go @@ -6,8 +6,9 @@ import ( "sync" "time" - "github.com/anyproto/any-sync/app/logger" "go.uber.org/zap" + + "github.com/anyproto/any-sync/app/logger" ) var ( @@ -137,10 +138,11 @@ Load: if reload { goto Load } - if load { - go c.load(ctx, id, e) - } c.metricsGet(!load) + if load { + c.load(ctx, id, e) + return e.value, e.loadErr + } return e.waitLoad(ctx, id) } diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 85a9c551..eef5c889 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -126,6 +126,9 @@ func TestOCache_Get(t *testing.T) { t.Run("context cancel", func(t *testing.T) { c := New(func(ctx context.Context, id string) (value Object, err error) { time.Sleep(time.Second / 3) + if ctx.Err() != nil { + return nil, ctx.Err() + } return &testObject{ name: "id", }, nil