Skip to content

Commit 2a9559d

Browse files
author
Brian Tiger Chow
committed
squash this is also moving ctxg
1 parent 6872ae8 commit 2a9559d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

core/core.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ type ConfigOption func(ctx context.Context) (*IpfsNode, error)
101101
func NewIPFSNode(parent context.Context, option ConfigOption) (*IpfsNode, error) {
102102
ctxg := ctxgroup.WithContext(parent)
103103
ctx := ctxg.Context()
104+
success := false // flip to true after all sub-system inits succeed
105+
defer func() {
106+
if !success {
107+
ctxg.Close()
108+
}
109+
}()
104110

105111
node, err := option(ctx)
106112
if err != nil {
@@ -126,6 +132,7 @@ func NewIPFSNode(parent context.Context, option ConfigOption) (*IpfsNode, error)
126132
node.Pinning = pin.NewPinner(node.Repo.Datastore(), node.DAG)
127133
}
128134
node.Resolver = &path.Resolver{DAG: node.DAG}
135+
success = true
129136
return node, nil
130137
}
131138

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

144-
success := false // flip to true after all sub-system inits succeed
145-
defer func() {
146-
if !success && n != nil {
147-
n.Close()
148-
}
149-
}()
150-
151151
if r == nil {
152152
return nil, debugerror.Errorf("repo required")
153153
}
@@ -183,7 +183,6 @@ func Standard(r repo.Repo, online bool) ConfigOption {
183183
n.Exchange = offline.Exchange(n.Blockstore)
184184
}
185185

186-
success = true
187186
return n, nil
188187
}
189188
}

0 commit comments

Comments
 (0)