From b3cfb352aeba5f89db14a860319df6c442f4bb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 16 Oct 2018 11:41:00 +0200 Subject: [PATCH] namesys: review fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- core/corehttp/gateway_test.go | 2 +- namesys/base.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 701f16f07a1a..e7e34af559bb 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -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 { diff --git a/namesys/base.go b/namesys/base.go index 56cfd03a242b..313b899ac906 100644 --- a/namesys/base.go +++ b/namesys/base.go @@ -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 { @@ -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) @@ -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