-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay.go
24 lines (19 loc) · 790 Bytes
/
delay.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
package httpfuncs
import (
"math/rand/v2"
"time"
"github.com/KJHJason/Cultured-Downloader-Logic/constants"
)
// Returns a random time.Duration between the given min and max arguments
func GetRandomTime(min, max float32) time.Duration {
randomDelay := min + rand.Float32()*(max-min)
return time.Duration(randomDelay*1000) * time.Millisecond
}
// Returns a random time.Duration between the given min and max arguments in the RetryDelay struct
func GetRandomDelay(delayInfo *RetryDelay) time.Duration {
return GetRandomTime(delayInfo.Min, delayInfo.Max)
}
// Returns a random time.Duration between the defined min and max delay values in the contants.go file
func GetDefaultRandomDelay() time.Duration {
return GetRandomTime(constants.MIN_RETRY_DELAY, constants.MAX_RETRY_DELAY)
}