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-ld-format
Commits
44a78014
Commit
44a78014
authored
Nov 15, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add contexts to Add/Remove methods
We'll need these for slower/remote datastores.
parent
f10b5dd9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
9 deletions
+10
-9
batch.go
batch.go
+2
-1
batch_test.go
batch_test.go
+4
-4
merkledag.go
merkledag.go
+4
-4
No files found.
batch.go
View file @
44a78014
package
format
import
(
"context"
"runtime"
cid
"github.com/ipfs/go-cid"
...
...
@@ -71,7 +72,7 @@ func (t *Batch) asyncCommit() {
}
}
go
func
(
b
[]
Node
)
{
err
:=
t
.
ds
.
AddMany
(
b
)
err
:=
t
.
ds
.
AddMany
(
context
.
Background
(),
b
)
t
.
commitResults
<-
err
}(
t
.
nodes
)
...
...
batch_test.go
View file @
44a78014
...
...
@@ -41,14 +41,14 @@ func (d *testDag) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *NodeOpti
return
out
}
func
(
d
*
testDag
)
Add
(
node
Node
)
error
{
func
(
d
*
testDag
)
Add
(
ctx
context
.
Context
,
node
Node
)
error
{
d
.
mu
.
Lock
()
defer
d
.
mu
.
Unlock
()
d
.
nodes
[
node
.
Cid
()
.
KeyString
()]
=
node
return
nil
}
func
(
d
*
testDag
)
AddMany
(
nodes
[]
Node
)
error
{
func
(
d
*
testDag
)
AddMany
(
ctx
context
.
Context
,
nodes
[]
Node
)
error
{
d
.
mu
.
Lock
()
defer
d
.
mu
.
Unlock
()
for
_
,
n
:=
range
nodes
{
...
...
@@ -57,14 +57,14 @@ func (d *testDag) AddMany(nodes []Node) error {
return
nil
}
func
(
d
*
testDag
)
Remove
(
c
*
cid
.
Cid
)
error
{
func
(
d
*
testDag
)
Remove
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
error
{
d
.
mu
.
Lock
()
defer
d
.
mu
.
Unlock
()
delete
(
d
.
nodes
,
c
.
KeyString
())
return
nil
}
func
(
d
*
testDag
)
RemoveMany
(
cids
[]
*
cid
.
Cid
)
error
{
func
(
d
*
testDag
)
RemoveMany
(
ctx
context
.
Context
,
cids
[]
*
cid
.
Cid
)
error
{
d
.
mu
.
Lock
()
defer
d
.
mu
.
Unlock
()
for
_
,
c
:=
range
cids
{
...
...
merkledag.go
View file @
44a78014
...
...
@@ -43,21 +43,21 @@ type DAGService interface {
NodeGetter
// Add adds a node to this DAG.
Add
(
Node
)
error
Add
(
context
.
Context
,
Node
)
error
// Remove removes a node from this DAG.
//
// Remove returns no error if the requested node is not present in this DAG.
Remove
(
*
cid
.
Cid
)
error
Remove
(
context
.
Context
,
*
cid
.
Cid
)
error
// AddMany adds many nodes to this DAG.
//
// Consider using NewBatch instead of calling this directly if you need
// to add an unbounded number of nodes to avoid buffering too much.
AddMany
([]
Node
)
error
AddMany
(
context
.
Context
,
[]
Node
)
error
// RemoveMany removes many nodes from this DAG.
//
// It returns success even if the nodes were not present in the DAG.
RemoveMany
([]
*
cid
.
Cid
)
error
RemoveMany
(
context
.
Context
,
[]
*
cid
.
Cid
)
error
}
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