MCPcopy Create free account
hub / github.com/cloud-native-go/examples / counter

Function counter

ch04/circuitbreaker_test.go:30–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28)
29
30func counter() Circuit {
31 m := sync.Mutex{}
32 count := 0
33
34 // Service function. Fails after 5 tries.
35 return func(ctx context.Context) (string, error) {
36 m.Lock()
37 count++
38 m.Unlock()
39
40 return fmt.Sprintf("%d", count), nil
41 }
42}
43
44// failAfter returns a function matching the Circuit type that returns an
45// error after its been called more than threshold times.

Callers 1

TestDebounceLastDataRaceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected