forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expiration.go
32 lines (27 loc) · 855 Bytes
/
expiration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package lazyref
import "time"
// NewSimpleExpirationProvider returns an expiration provider
// that sets the given expiration period
func NewSimpleExpirationProvider(expiry time.Duration) ExpirationProvider {
return func() time.Duration {
return expiry
}
}
// NewGraduatingExpirationProvider returns an expiration provider
// that has an initial expiration and then expires in graduated increments
// with a maximum expiration time.
func NewGraduatingExpirationProvider(initialExpiry, increments, maxExpiry time.Duration) ExpirationProvider {
var iteration uint32
return func() time.Duration {
expiry := initialExpiry + time.Duration(iteration)*increments
if expiry > maxExpiry {
return maxExpiry
}
iteration++
return expiry
}
}