feat: add subscriptions and rework interfaces

This commit is contained in:
Jon Lundy
2022-08-09 16:23:33 -06:00
parent 82f23ae323
commit 0642879c07
16 changed files with 1368 additions and 627 deletions

View File

@@ -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()