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
1535a6a9
Commit
1535a6a9
authored
Jan 27, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow promises to fail
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
7df6213e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
merkledag.go
merkledag.go
+12
-0
No files found.
merkledag.go
View file @
1535a6a9
...
@@ -192,6 +192,9 @@ func GetNodes(ctx context.Context, ds DAGService, keys []key.Key) []NodeGetter {
...
@@ -192,6 +192,9 @@ func GetNodes(ctx context.Context, ds DAGService, keys []key.Key) []NodeGetter {
select
{
select
{
case
opt
,
ok
:=
<-
nodechan
:
case
opt
,
ok
:=
<-
nodechan
:
if
!
ok
{
if
!
ok
{
for
_
,
p
:=
range
promises
{
p
.
Fail
(
ErrNotFound
)
}
return
return
}
}
...
@@ -239,6 +242,7 @@ func newNodePromise(ctx context.Context) (NodeGetter, chan<- *Node) {
...
@@ -239,6 +242,7 @@ func newNodePromise(ctx context.Context) (NodeGetter, chan<- *Node) {
return
&
nodePromise
{
return
&
nodePromise
{
recv
:
ch
,
recv
:
ch
,
ctx
:
ctx
,
ctx
:
ctx
,
err
:
make
(
chan
error
,
1
),
},
ch
},
ch
}
}
...
@@ -246,6 +250,7 @@ type nodePromise struct {
...
@@ -246,6 +250,7 @@ type nodePromise struct {
cache
*
Node
cache
*
Node
recv
<-
chan
*
Node
recv
<-
chan
*
Node
ctx
context
.
Context
ctx
context
.
Context
err
chan
error
}
}
// NodeGetter provides a promise like interface for a dag Node
// NodeGetter provides a promise like interface for a dag Node
...
@@ -254,6 +259,11 @@ type nodePromise struct {
...
@@ -254,6 +259,11 @@ type nodePromise struct {
// cached node.
// cached node.
type
NodeGetter
interface
{
type
NodeGetter
interface
{
Get
(
context
.
Context
)
(
*
Node
,
error
)
Get
(
context
.
Context
)
(
*
Node
,
error
)
Fail
(
err
error
)
}
func
(
np
*
nodePromise
)
Fail
(
err
error
)
{
np
.
err
<-
err
}
}
func
(
np
*
nodePromise
)
Get
(
ctx
context
.
Context
)
(
*
Node
,
error
)
{
func
(
np
*
nodePromise
)
Get
(
ctx
context
.
Context
)
(
*
Node
,
error
)
{
...
@@ -268,6 +278,8 @@ func (np *nodePromise) Get(ctx context.Context) (*Node, error) {
...
@@ -268,6 +278,8 @@ func (np *nodePromise) Get(ctx context.Context) (*Node, error) {
return
nil
,
np
.
ctx
.
Err
()
return
nil
,
np
.
ctx
.
Err
()
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
return
nil
,
ctx
.
Err
()
case
err
:=
<-
np
.
err
:
return
nil
,
err
}
}
return
np
.
cache
,
nil
return
np
.
cache
,
nil
}
}
...
...
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