-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmeter.go
37 lines (31 loc) · 972 Bytes
/
meter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package dstore
import (
"context"
)
// Deprecated: This interface will no longer be used, use the Options to inject all metering logic from the upstream code instead
type Meter interface {
AddBytesRead(int)
AddBytesWritten(int)
}
// Deprecated: Use the Options to add callbacks to inject metering from the upstream code instead
func (c *commonStore) SetMeter(meter Meter) {
//imitate the old behavior:
rcb := func(ctx context.Context, n int) {}
if c.compressedReadCallback != nil {
rcb = c.compressedReadCallback
}
c.compressedReadCallback = func(ctx context.Context, n int) {
meter.AddBytesRead(n)
rcb(ctx, n)
}
wcb := func(ctx context.Context, n int) {}
if c.uncompressedWriteCallback != nil {
wcb = c.uncompressedWriteCallback
}
c.uncompressedWriteCallback = func(ctx context.Context, n int) {
meter.AddBytesWritten(n)
wcb(ctx, n)
}
}
// Deprecated: SetMeter on MockStore no longer does anything
func (_ *MockStore) SetMeter(_ Meter) {}