AmitKumarDas / Decisions

Apache License 2.0
10 stars 3 forks source link

Go: Long running operation - context #230

Open AmitKumarDas opened 4 years ago

AmitKumarDas commented 4 years ago

In Go, a long running or expensive operation typically accepts a context that the consumer can use to cancel (stop) the operation.

ctx, cancel := context.WithTimeout(context.Background(), h.Timeout)
defer cancel()

publishInfo, _, err := h.attacher.Attach(
  ctx, 
  volumeHandle, 
  readOnly, 
  nodeID, 
  volumeCapabilities, 
  attributes, 
  secrets,
)
if err != nil {
  return va, nil, err
}