Skip to content

Commit

Permalink
namesys: review fixes
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
  • Loading branch information
magik6k committed Oct 16, 2018
1 parent 94bbeff commit b3cfb35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m mockNamesys) ResolveAsync(ctx context.Context, name string, opts ...nsop
v, err := m.Resolve(ctx, name, opts...)
out <- namesys.Result{Path: v, Err: err}
close(out)
return nil
return out
}

func (m mockNamesys) Publish(ctx context.Context, name ci.PrivKey, value path.Path) error {
Expand Down
15 changes: 9 additions & 6 deletions namesys/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (

context "context"

opts "github.com/ipfs/go-ipfs/namesys/opts"
path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"

opts "github.com/ipfs/go-ipfs/namesys/opts"
)

type onceResult struct {
Expand Down Expand Up @@ -40,13 +41,10 @@ func resolve(ctx context.Context, r resolver, name string, options opts.ResolveO
return p, err
}

//TODO:
// - better error handling
// - select on writes
func resolveAsync(ctx context.Context, r resolver, name string, options opts.ResolveOpts, prefix string) <-chan Result {
resCh := r.resolveOnceAsync(ctx, name, options)
depth := options.Depth
outCh := make(chan Result)
outCh := make(chan Result, 1)

go func() {
defer close(outCh)
Expand Down Expand Up @@ -97,8 +95,13 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
break
}

outCh <- res
select {
case outCh <- res:
case <-ctx.Done():
return
}
case <-ctx.Done():
return
}
if resCh == nil && subCh == nil {
return
Expand Down

0 comments on commit b3cfb35

Please sign in to comment.