feat: add subscriptions and rework interfaces
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package locker
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Locked[T any] struct {
|
||||
state chan *T
|
||||
@@ -23,6 +26,9 @@ func (s *Locked[T]) Modify(ctx context.Context, fn func(*T) error) error {
|
||||
select {
|
||||
case state := <-s.state:
|
||||
defer func() { s.state <- state }()
|
||||
log.Printf("locker %T to %p", state, fn)
|
||||
defer log.Printf("locker %T from %p", state, fn)
|
||||
|
||||
return fn(state)
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
|
||||
Reference in New Issue
Block a user