Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-cidutil
Commits
4de263a9
Commit
4de263a9
authored
Aug 10, 2018
by
Łukasz Magiera
Committed by
Steven Allen
Aug 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a streaming CID set
used in
https://github.com/ipfs/go-ipfs/pull/4804
parent
99995a30
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
set.go
set.go
+35
-0
No files found.
set.go
View file @
4de263a9
package
cid
import
(
"context"
)
// Set is a implementation of a set of Cids, that is, a structure
// to which holds a single copy of every Cids that is added to it.
type
Set
struct
{
...
...
@@ -65,3 +69,34 @@ func (s *Set) ForEach(f func(c *Cid) error) error {
}
return
nil
}
// StreamingSet is an extension of Set which allows to implement back-pressure
// for the Visit function
type
StreamingSet
struct
{
Set
*
Set
New
chan
*
Cid
}
// NewStreamingSet initializes and returns new Set.
func
NewStreamingSet
()
*
StreamingSet
{
return
&
StreamingSet
{
Set
:
NewSet
(),
New
:
make
(
chan
*
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
*
Cid
)
bool
{
return
func
(
c
*
Cid
)
bool
{
if
s
.
Set
.
Visit
(
c
)
{
select
{
case
s
.
New
<-
c
:
case
<-
ctx
.
Done
()
:
}
return
true
}
return
false
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment