mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 11:11:26 +00:00
Merge pull request #108 from aykhans/core/refactor-duration-logic
All checks were successful
golangci-lint / lint (push) Successful in 3m4s
All checks were successful
golangci-lint / lint (push) Successful in 3m4s
🔨 Replace 'time.AfterFunc' with 'context.WithTimeout'
This commit is contained in:
commit
cb8898d20e
@ -20,8 +20,11 @@ import (
|
|||||||
// - ctx: The context for managing request lifecycle and cancellation.
|
// - ctx: The context for managing request lifecycle and cancellation.
|
||||||
// - requestConfig: The configuration for the request, including timeout, proxies, and other settings.
|
// - requestConfig: The configuration for the request, including timeout, proxies, and other settings.
|
||||||
func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) {
|
func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
if requestConfig.Duration > 0 {
|
||||||
defer cancel()
|
var cancel context.CancelFunc
|
||||||
|
ctx, cancel = context.WithTimeout(ctx, requestConfig.Duration)
|
||||||
|
defer cancel()
|
||||||
|
}
|
||||||
|
|
||||||
clients := getClients(
|
clients := getClients(
|
||||||
ctx,
|
ctx,
|
||||||
@ -34,10 +37,6 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e
|
|||||||
return nil, types.ErrInterrupt
|
return nil, types.ErrInterrupt
|
||||||
}
|
}
|
||||||
|
|
||||||
if requestConfig.Duration > 0 {
|
|
||||||
time.AfterFunc(requestConfig.Duration, func() { cancel() })
|
|
||||||
}
|
|
||||||
|
|
||||||
responses := releaseDodos(ctx, requestConfig, clients)
|
responses := releaseDodos(ctx, requestConfig, clients)
|
||||||
if ctx.Err() != nil && len(responses) == 0 {
|
if ctx.Err() != nil && len(responses) == 0 {
|
||||||
return nil, types.ErrInterrupt
|
return nil, types.ErrInterrupt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user