Skip to content

Commit

Permalink
SharedLock -> Touch
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Mar 24, 2024
1 parent c28ddc7 commit e079f4f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (c *conn) Invoke(
return c.wrapError(err)
}

defer c.lastUsage.SharedLock()()
defer c.lastUsage.Touch()()

ctx, traceID, err := meta.TraceID(ctx)
if err != nil {
Expand Down Expand Up @@ -411,7 +411,7 @@ func (c *conn) NewStream(
return nil, c.wrapError(err)
}

defer c.lastUsage.SharedLock()()
defer c.lastUsage.Touch()()

ctx, traceID, err := meta.TraceID(ctx)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/conn/grpc_client_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *grpcClientStream) CloseSend() (err error) {
onDone(err)
}()

defer s.c.lastUsage.SharedLock()()
defer s.c.lastUsage.Touch()()

err = s.ClientStream.CloseSend()

Expand Down Expand Up @@ -61,7 +61,7 @@ func (s *grpcClientStream) SendMsg(m interface{}) (err error) {
onDone(err)
}()

defer s.c.lastUsage.SharedLock()()
defer s.c.lastUsage.Touch()()

err = s.ClientStream.SendMsg(m)

Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *grpcClientStream) RecvMsg(m interface{}) (err error) {
onDone(err)
}()

defer s.c.lastUsage.SharedLock()()
defer s.c.lastUsage.Touch()()

defer func() {
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/conn/last_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (l *lastUsage) Get() time.Time {
return l.clock.Now()
}

func (l *lastUsage) SharedLock() (releaseFunc func()) {
func (l *lastUsage) Touch() (releaseFunc func()) {
l.locks.Add(1)

return sync.OnceFunc(func() {
Expand Down
10 changes: 5 additions & 5 deletions internal/conn/last_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_lastUsage_Lock(t *testing.T) {
lu.t.Store(&start)
t1 := lu.Get()
require.Equal(t, start, t1)
f := lu.SharedLock()
f := lu.Touch()
clock.Advance(time.Hour)
t2 := lu.Get()
require.Equal(t, start.Add(time.Hour), t2)
Expand All @@ -39,14 +39,14 @@ func Test_lastUsage_Lock(t *testing.T) {
lu.t.Store(&start)
t1 := lu.Get()
require.Equal(t, start, t1)
f1 := lu.SharedLock()
f1 := lu.Touch()
clock.Advance(time.Hour)
t2 := lu.Get()
require.Equal(t, start.Add(time.Hour), t2)
f2 := lu.SharedLock()
f2 := lu.Touch()
clock.Advance(time.Hour)
f1()
f3 := lu.SharedLock()
f3 := lu.Touch()
clock.Advance(time.Hour)
t3 := lu.Get()
require.Equal(t, start.Add(3*time.Hour), t3)
Expand Down Expand Up @@ -83,7 +83,7 @@ func Test_lastUsage_Lock(t *testing.T) {
t2 := lu.Get()
require.Equal(t, start, t2)
clock.Advance(time.Hour)
defer lu.SharedLock()()
defer lu.Touch()()
t3 := lu.Get()
require.Equal(t, start.Add(2*time.Hour), t3)
clock.Advance(time.Hour)
Expand Down

0 comments on commit e079f4f

Please sign in to comment.