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-merkledag
Commits
be9e1d21
Commit
be9e1d21
authored
Oct 31, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make FetchGraph waitable
parent
03fab00c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
merkledag.go
merkledag.go
+19
-2
No files found.
merkledag.go
View file @
be9e1d21
...
@@ -2,6 +2,7 @@ package merkledag
...
@@ -2,6 +2,7 @@ package merkledag
import
(
import
(
"fmt"
"fmt"
"sync"
"time"
"time"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
@@ -242,9 +243,16 @@ func (n *dagService) Remove(nd *Node) error {
...
@@ -242,9 +243,16 @@ func (n *dagService) Remove(nd *Node) error {
return
n
.
Blocks
.
DeleteBlock
(
k
)
return
n
.
Blocks
.
DeleteBlock
(
k
)
}
}
func
FetchGraph
(
ctx
context
.
Context
,
root
*
Node
,
serv
DAGService
)
{
func
FetchGraph
(
ctx
context
.
Context
,
root
*
Node
,
serv
DAGService
)
chan
struct
{}
{
var
wg
sync
.
WaitGroup
done
:=
make
(
chan
struct
{})
for
_
,
l
:=
range
root
.
Links
{
for
_
,
l
:=
range
root
.
Links
{
wg
.
Add
(
1
)
go
func
(
lnk
*
Link
)
{
go
func
(
lnk
*
Link
)
{
// Signal child is done on way out
defer
wg
.
Done
()
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
return
...
@@ -255,7 +263,16 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) {
...
@@ -255,7 +263,16 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) {
log
.
Error
(
err
)
log
.
Error
(
err
)
return
return
}
}
FetchGraph
(
ctx
,
nd
,
serv
)
// Wait for children to finish
<-
FetchGraph
(
ctx
,
nd
,
serv
)
}(
l
)
}(
l
)
}
}
go
func
()
{
wg
.
Wait
()
done
<-
struct
{}{}
}()
return
done
}
}
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