TIMEOUTS Calls a function, synchronously, while imposing a timeout on the Database's Context. Any call to CheckTimeout while the function is running will return an error if the timeout has expired. The function will *not* be aborted automatically! Its code must check for timeouts by calling CheckTim
(ctx context.Context, timeout time.Duration, operation func(tmCtx context.Context) error)
| 2138 | // Calls a function, synchronously, while imposing a timeout on the Database's Context. Any call to CheckTimeout while the function is running will return an error if the timeout has expired. |
| 2139 | // The function will *not* be aborted automatically! Its code must check for timeouts by calling CheckTimeout periodically, returning once that produces an error. |
| 2140 | func WithTimeout(ctx context.Context, timeout time.Duration, operation func(tmCtx context.Context) error) error { |
| 2141 | newCtx, cancel := context.WithTimeout(ctx, timeout) |
| 2142 | defer func() { |
| 2143 | cancel() |
| 2144 | }() |
| 2145 | return operation(newCtx) |
| 2146 | } |
| 2147 | |
| 2148 | // Returns an HTTP timeout (408) error if the Database's Context has an expired timeout or has been explicitly canceled. (See WithTimeout.) |
| 2149 | func CheckTimeout(ctx context.Context) error { |
no outgoing calls
no test coverage detected