Debian Codegraph @

pkg/util/flowcontrol/counter/interface.go

raw
1 /*
2 Copyright 2019 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package counter
18
19 // GoRoutineCounter keeps track of the number of active goroutines
20 // working on/for something. This is a utility that makes such code more
21 // testable. The code uses this utility to report the number of active
22 // goroutines to the test code, so that the test code can advance a fake
23 // clock when and only when the code being tested has finished all
24 // the work that is ready to do at the present time.
25 type GoRoutineCounter interface {
26 // Add adds the given delta to the count of active goroutines.
27 // Call Add(1) before forking a goroutine, Add(-1) at the end of that goroutine.
28 // Call Add(-1) just before waiting on something from another goroutine (e.g.,
29 // just before a `select`).
30 // Call Add(1) just before doing something that unblocks a goroutine that is
31 // waiting on that something.
32 Add(delta int)
33 }