From 19db4ce4e3e966c3edeb7946dc604c766e4bcd01 Mon Sep 17 00:00:00 2001 From: Michael Avila Date: Wed, 12 Jun 2019 13:02:41 -0700 Subject: [PATCH] Either timeout or not --- simple/provider.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/simple/provider.go b/simple/provider.go index 9b374a0..8d514d6 100644 --- a/simple/provider.go +++ b/simple/provider.go @@ -5,6 +5,7 @@ package simple import ( "context" + "fmt" "time" "github.com/ipfs/go-cid" @@ -88,13 +89,20 @@ func (p *Provider) handleAnnouncements() { case <-p.ctx.Done(): return case c := <-p.queue.Dequeue(): - ctx, cancel := context.WithTimeout(p.ctx, p.timeout) - defer cancel() - logP.Info("announce - start - ", c) + var ctx context.Context + var cancel context.CancelFunc + if p.timeout > 0 { + ctx, cancel = context.WithTimeout(p.ctx, p.timeout) + defer cancel() + } else { + ctx = p.ctx + } + + fmt.Println("announce - start - ", c) if err := p.contentRouting.Provide(ctx, c, true); err != nil { logP.Warningf("Unable to provide entry: %s, %s", c, err) } - logP.Info("announce - end - ", c) + fmt.Println("announce - end - ", c) } } }()