feat: add resolvelinks
This commit is contained in:
@@ -19,7 +19,7 @@ func New[T any](initial *T) *Locked[T] {
|
||||
}
|
||||
|
||||
// Modify will call the function with the locked value
|
||||
func (s *Locked[T]) Modify(ctx context.Context, fn func(*T) error) error {
|
||||
func (s *Locked[T]) Modify(ctx context.Context, fn func(context.Context, *T) error) error {
|
||||
_, span := lg.Span(ctx)
|
||||
defer span.End()
|
||||
|
||||
@@ -30,7 +30,7 @@ func (s *Locked[T]) Modify(ctx context.Context, fn func(*T) error) error {
|
||||
select {
|
||||
case state := <-s.state:
|
||||
defer func() { s.state <- state }()
|
||||
return fn(state)
|
||||
return fn(ctx, state)
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (s *Locked[T]) Modify(ctx context.Context, fn func(*T) error) error {
|
||||
func (s *Locked[T]) Copy(ctx context.Context) (T, error) {
|
||||
var t T
|
||||
|
||||
err := s.Modify(ctx, func(c *T) error {
|
||||
err := s.Modify(ctx, func(ctx context.Context, c *T) error {
|
||||
if c != nil {
|
||||
t = *c
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestLocker(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
err := value.Modify(ctx, func(c *config) error {
|
||||
err := value.Modify(ctx, func(ctx context.Context, c *config) error {
|
||||
c.Value = "one"
|
||||
c.Counter++
|
||||
return nil
|
||||
@@ -37,7 +37,7 @@ func TestLocker(t *testing.T) {
|
||||
|
||||
wait := make(chan struct{})
|
||||
|
||||
go value.Modify(ctx, func(c *config) error {
|
||||
go value.Modify(ctx, func(ctx context.Context, c *config) error {
|
||||
c.Value = "two"
|
||||
c.Counter++
|
||||
close(wait)
|
||||
@@ -47,7 +47,7 @@ func TestLocker(t *testing.T) {
|
||||
<-wait
|
||||
cancel()
|
||||
|
||||
err = value.Modify(ctx, func(c *config) error {
|
||||
err = value.Modify(ctx, func(ctx context.Context, c *config) error {
|
||||
c.Value = "three"
|
||||
c.Counter++
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user