Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Either timeout or not
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelavila committed Jun 12, 2019
1 parent c3bccce commit 19db4ce
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions simple/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package simple

import (
"context"
"fmt"
"time"

"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -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)
}
}
}()
Expand Down

0 comments on commit 19db4ce

Please sign in to comment.