github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/operation/params.go (about)

     1  package operation
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"
     8  )
     9  
    10  func Params(
    11  	ctx context.Context,
    12  	timeout time.Duration,
    13  	cancelAfter time.Duration,
    14  	mode Mode,
    15  ) *Ydb_Operations.OperationParams {
    16  	if d, ok := Timeout(ctx); ok {
    17  		timeout = d
    18  	}
    19  	if d, ok := CancelAfter(ctx); ok {
    20  		cancelAfter = d
    21  	}
    22  	if d, ok := untilDeadline(ctx); mode == ModeSync && ok && d < timeout {
    23  		timeout = d
    24  	}
    25  	if timeout == 0 && cancelAfter == 0 && mode == 0 {
    26  		return nil
    27  	}
    28  
    29  	return &Ydb_Operations.OperationParams{
    30  		OperationMode:    mode.toYDB(),
    31  		OperationTimeout: timeoutParam(timeout),
    32  		CancelAfter:      timeoutParam(cancelAfter),
    33  	}
    34  }