Skip to content

Commit

Permalink
check close channel before add (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
nar10z committed Jul 8, 2024
1 parent e3c88e5 commit 3a9dd27
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ func (a *Accumulator[T]) AddAsync(ctx context.Context, event T) error {
}

func (a *Accumulator[T]) AddSync(ctx context.Context, event T) error {
if a.isClose.Load() {
return ErrSendToClose
}

// check context before alloc eventExtended
select {
case <-ctx.Done():
Expand All @@ -103,6 +99,10 @@ func (a *Accumulator[T]) AddSync(ctx context.Context, event T) error {
e: event,
}

if a.isClose.Load() {
return ErrSendToClose
}

// check context with write to channel
select {
case <-ctx.Done():
Expand Down

0 comments on commit 3a9dd27

Please sign in to comment.