-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathset.go
More file actions
42 lines (34 loc) · 778 Bytes
/
set.go
File metadata and controls
42 lines (34 loc) · 778 Bytes
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
package cidutil
import (
"context"
c "github.com/ipfs/go-cid"
)
type Set = c.Set
func NewSet() *Set { return c.NewSet() }
// StreamingSet is an extension of Set which allows to implement back-pressure
// for the Visit function
type StreamingSet struct {
Set *Set
New chan c.Cid
}
// NewStreamingSet initializes and returns new Set.
func NewStreamingSet() *StreamingSet {
return &StreamingSet{
Set: c.NewSet(),
New: make(chan c.Cid),
}
}
// Visitor creates new visitor which adds a Cids to the set and emits them to
// the set.New channel
func (s *StreamingSet) Visitor(ctx context.Context) func(c c.Cid) bool {
return func(c c.Cid) bool {
if s.Set.Visit(c) {
select {
case s.New <- c:
case <-ctx.Done():
}
return true
}
return false
}
}