diff --git a/pkg/blobserver/blobhub.go b/pkg/blobserver/blobhub.go index 0c96a5e8f..8b136df75 100644 --- a/pkg/blobserver/blobhub.go +++ b/pkg/blobserver/blobhub.go @@ -99,10 +99,14 @@ func WaitForBlob(storage interface{}, deadline time.Time, blobs []blob.Ref) { if !canLongPoll { tc = time.After(2 * time.Second) } + + t := time.NewTimer(time.Until(deadline)) + defer t.Stop() + select { case <-ch: case <-tc: - case <-time.After(deadline.Sub(time.Now())): + case <-t.C: } } diff --git a/pkg/importer/pinboard/pinboard.go b/pkg/importer/pinboard/pinboard.go index cf080ffc8..51f975f97 100644 --- a/pkg/importer/pinboard/pinboard.go +++ b/pkg/importer/pinboard/pinboard.go @@ -243,7 +243,7 @@ type apiPost struct { } func (r *run) importBatch(authToken string, parent *importer.Object) (keepTrying bool, err error) { - sleepDuration := r.nextAfter.Sub(time.Now()) + sleepDuration := time.Until(r.nextAfter) // block until we either get canceled or until it is time to run select { case <-r.Context().Done(): @@ -307,7 +307,7 @@ func (r *run) importBatch(authToken string, parent *importer.Object) (keepTrying }) } - log.Printf("pinboard: Imported batch of %d posts in %s.", postCount, time.Now().Sub(start)) + log.Printf("pinboard: Imported batch of %d posts in %s.", postCount, time.Since(start)) r.nextCursor = postBatch[postCount-1].Time r.lastPause = pauseInterval