github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/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  //
    11  // Deprecated: use retry.WithIdempotent option instead.
    12  // Will be removed after Oct 2024.
    13  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
    14  func WithIdempotentOperation(ctx context.Context) context.Context {
    15  	return context.WithValue(ctx, ctxIsOperationIdempotentKey{}, true)
    16  }
    17  
    18  // WithNonIdempotentOperation returns a copy of parent context with non-idempotent operation feature
    19  //
    20  // Deprecated: idempotent flag is false by default.
    21  // Will be removed after Oct 2024.
    22  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
    23  func WithNonIdempotentOperation(ctx context.Context) context.Context {
    24  	return context.WithValue(ctx, ctxIsOperationIdempotentKey{}, false)
    25  }
    26  
    27  // IsOperationIdempotent returns the flag for retry with no idempotent errors
    28  //
    29  // Deprecated: context cannot store idempotent value now.
    30  // Will be removed after Oct 2024.
    31  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
    32  func IsOperationIdempotent(ctx context.Context) bool {
    33  	v, ok := ctx.Value(ctxIsOperationIdempotentKey{}).(bool)
    34  
    35  	return ok && v
    36  }