-
Notifications
You must be signed in to change notification settings - Fork 2
/
collection_noop.go
65 lines (53 loc) · 934 Bytes
/
collection_noop.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"sync"
"time"
)
type NoopCollection struct {
sync.RWMutex
sync.WaitGroup
n int
}
func NewNoopCollection() (c Collection, err error) {
return &NoopCollection{}, nil
}
func (c *NoopCollection) Close(force bool) (err error) {
return nil
}
func (c *NoopCollection) Rows() (ch chan Row) {
ch = make(chan Row, 1000)
go func(ch chan Row) {
defer close(ch)
c.RLock()
n := c.n
c.RUnlock()
row := Row{Key: RowKey{}, Value: &RowValue{}}
for i := 0; i < n; i++ {
ch <- row
}
}(ch)
return ch
}
func (c *NoopCollection) Set(rows []*Row) (err error) {
c.Lock()
c.n += len(rows)
c.Unlock()
return nil
}
func (c *NoopCollection) Delete(k RowKey) (err error) {
c.Lock()
if c.n > 0 {
c.n = c.n - 1
}
c.Unlock()
return nil
}
func (c *NoopCollection) Timing() (int, time.Duration) {
t0 := time.Now()
n := 0
for range c.Rows() {
n++
}
t1 := time.Now()
return n, t1.Sub(t0)
}