-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctx.go
27 lines (23 loc) · 792 Bytes
/
ctx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package util
import (
"context"
"errors"
)
// ErrOperationCancelled is return, when operation cancelled via context
var ErrOperationCancelled = errors.New("blockstorage: operation context cancelled")
// ErrOperationTimedOut is return, when operation deadline exceeded
var ErrOperationTimedOut = errors.New("blockstorage: operation timed out")
// CheckContext - checks context has error. If context has not err returns nil.
// Otherwise operates following
// - `context.DeadlineExceeded` returns `ErrOperationTimedOut`
// - `context.Canceled` returns `ErrOperationCancelled`
func CheckContext(ctx context.Context) error {
switch ctx.Err() {
case context.DeadlineExceeded:
return ErrOperationTimedOut
case context.Canceled:
return ErrOperationCancelled
default:
return nil
}
}