Skip to content

Commit

Permalink
squash this is also moving ctxg
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Tiger Chow committed Jan 16, 2015
1 parent 6872ae8 commit 2a9559d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ type ConfigOption func(ctx context.Context) (*IpfsNode, error)
func NewIPFSNode(parent context.Context, option ConfigOption) (*IpfsNode, error) {
ctxg := ctxgroup.WithContext(parent)
ctx := ctxg.Context()
success := false // flip to true after all sub-system inits succeed
defer func() {
if !success {
ctxg.Close()
}
}()

node, err := option(ctx)
if err != nil {
Expand All @@ -126,6 +132,7 @@ func NewIPFSNode(parent context.Context, option ConfigOption) (*IpfsNode, error)
node.Pinning = pin.NewPinner(node.Repo.Datastore(), node.DAG)
}
node.Resolver = &path.Resolver{DAG: node.DAG}
success = true
return node, nil
}

Expand All @@ -141,13 +148,6 @@ func Online(r repo.Repo) ConfigOption {
func Standard(r repo.Repo, online bool) ConfigOption {
return func(ctx context.Context) (n *IpfsNode, err error) {

success := false // flip to true after all sub-system inits succeed
defer func() {
if !success && n != nil {
n.Close()
}
}()

if r == nil {
return nil, debugerror.Errorf("repo required")
}
Expand Down Expand Up @@ -183,7 +183,6 @@ func Standard(r repo.Repo, online bool) ConfigOption {
n.Exchange = offline.Exchange(n.Blockstore)
}

success = true
return n, nil
}
}
Expand Down

0 comments on commit 2a9559d

Please sign in to comment.