mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-15 11:13:37 +08:00

- Modified Godeps/Godeps.json by hand - [TEST] Updated welcome docs hash to sharness - [TEST] Updated contact doc - [TEST] disabled breaking test (t0080-repo refs local)
23 lines
507 B
Go
23 lines
507 B
Go
package ctxutil
|
|
|
|
import (
|
|
"time"
|
|
|
|
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
)
|
|
|
|
func WithDeadlineFraction(ctx context.Context, fraction float64) (context.Context, context.CancelFunc) {
|
|
d, found := ctx.Deadline()
|
|
if !found { // no deadline
|
|
return context.WithCancel(ctx)
|
|
}
|
|
|
|
left := d.Sub(time.Now())
|
|
if left < 0 { // already passed...
|
|
return context.WithCancel(ctx)
|
|
}
|
|
|
|
left = time.Duration(float64(left) * fraction)
|
|
return context.WithTimeout(ctx, left)
|
|
}
|