Skip to content

Commit

Permalink
get method for atomic counters
Browse files Browse the repository at this point in the history
  • Loading branch information
Termina1 committed Dec 16, 2024
1 parent cde0087 commit 016693d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions atomic_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ func (a *AtomicCounter) load() error {
return nil
}

func (a *AtomicCounter) Get(ctx context.Context) (int64, error) {
err := a.load()
if err != nil {
return 0, err
}
if !a.loaded.Load() {
return 0, ErrCounterNotLoaded
}
return a.localValue.Load(), nil
}

// Loads (if needed) and increments counter
func (a *AtomicCounter) Increment(ctx context.Context, val int64) (int64, error) {
err := a.load()
Expand Down

0 comments on commit 016693d

Please sign in to comment.