mirror of https://github.com/perkeep/perkeep.git
pkg: simplify code - use time.Until and time.Since
Change-Id: I9c023bd4bb312e05bfbd6b1e33425500bbc5aada
This commit is contained in:
parent
4f4da7aa21
commit
680b296c2e
|
@ -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:
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue