feat(locker): add check for nested calls

This commit is contained in:
Jon Lundy
2023-03-19 08:31:00 -06:00
parent d27eb21ffb
commit fcc5d08aa7
12 changed files with 87 additions and 40 deletions

View File

@@ -76,7 +76,7 @@ func (s *streamer) Subscribe(ctx context.Context, streamID string, start int64)
})
sub.unsub = s.delete(streamID, sub)
return sub, s.state.Modify(ctx, func(ctx context.Context, state *state) error {
return sub, s.state.Use(ctx, func(ctx context.Context, state *state) error {
state.subscribers[streamID] = append(state.subscribers[streamID], sub)
return nil
})
@@ -85,14 +85,14 @@ func (s *streamer) Send(ctx context.Context, streamID string, events event.Event
ctx, span := lg.Span(ctx)
defer span.End()
return s.state.Modify(ctx, func(ctx context.Context, state *state) error {
return s.state.Use(ctx, func(ctx context.Context, state *state) error {
ctx, span := lg.Span(ctx)
defer span.End()
span.AddEvent(fmt.Sprint("subscribers=", len(state.subscribers[streamID])))
for _, sub := range state.subscribers[streamID] {
err := sub.position.Modify(ctx, func(ctx context.Context, position *position) error {
err := sub.position.Use(ctx, func(ctx context.Context, position *position) error {
ctx, span := lg.Span(ctx)
defer span.End()
@@ -128,7 +128,7 @@ func (s *streamer) delete(streamID string, sub *subscription) func(context.Conte
if err := ctx.Err(); err != nil {
return err
}
return s.state.Modify(ctx, func(ctx context.Context, state *state) error {
return s.state.Use(ctx, func(ctx context.Context, state *state) error {
_, span := lg.Span(ctx)
defer span.End()
@@ -228,7 +228,7 @@ func (s *subscription) Recv(ctx context.Context) <-chan bool {
var wait func(context.Context) bool
defer close(done)
err := s.position.Modify(ctx, func(ctx context.Context, position *position) error {
err := s.position.Use(ctx, func(ctx context.Context, position *position) error {
_, span := lg.Span(ctx)
defer span.End()
@@ -280,7 +280,7 @@ func (s *subscription) Events(ctx context.Context) (event.Events, error) {
defer span.End()
var events event.Events
return events, s.position.Modify(ctx, func(ctx context.Context, position *position) error {
return events, s.position.Use(ctx, func(ctx context.Context, position *position) error {
ctx, span := lg.Span(ctx)
defer span.End()