github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/retry/context.go (about)

     1  package retry
     2  
     3  import "context"
     4  
     5  type (
     6  	ctxIsOperationIdempotentKey struct{}
     7  )
     8  
     9  // WithIdempotentOperation returns a copy of parent context with idempotent operation feature
    10  // Deprecated: use retry.WithIdempotent option instead
    11  func WithIdempotentOperation(ctx context.Context) context.Context {
    12  	return context.WithValue(ctx, ctxIsOperationIdempotentKey{}, true)
    13  }
    14  
    15  // WithNonIdempotentOperation returns a copy of parent context with non-idempotent operation feature
    16  // Deprecated: idempotent flag is false by default
    17  func WithNonIdempotentOperation(ctx context.Context) context.Context {
    18  	return context.WithValue(ctx, ctxIsOperationIdempotentKey{}, false)
    19  }
    20  
    21  // IsOperationIdempotent returns the flag for retry with no idempotent errors
    22  // Deprecated: context cannot store idempotent value now
    23  func IsOperationIdempotent(ctx context.Context) bool {
    24  	v, ok := ctx.Value(ctxIsOperationIdempotentKey{}).(bool)
    25  
    26  	return ok && v
    27  }