Preserve operation timeout identity during HTTP generation
This commit is contained in:
@@ -3,6 +3,7 @@ package usecase
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,9 @@ type OperationScope struct {
|
||||
func NewOperationScope(parent context.Context, duration time.Duration) *OperationScope {
|
||||
scope := &OperationScope{Context: parent, cancel: func() {}}
|
||||
if duration > 0 {
|
||||
scope.cause = errors.New("operation deadline")
|
||||
// Transports may return context.Cause rather than ctx.Err(). Retain
|
||||
// deadline identity while keeping this cause unique to the invocation.
|
||||
scope.cause = fmt.Errorf("operation deadline: %w", context.DeadlineExceeded)
|
||||
scope.Context, scope.cancel = context.WithTimeoutCause(parent, duration, scope.cause)
|
||||
}
|
||||
return scope
|
||||
|
||||
Reference in New Issue
Block a user