-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpriority.go
More file actions
35 lines (28 loc) · 967 Bytes
/
priority.go
File metadata and controls
35 lines (28 loc) · 967 Bytes
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
28
29
30
31
32
33
34
35
// Copyright (c) 2026 Onur Cinar.
// The source code is provided under MIT License.
// https://github.com/cinar/resile
package resile
import "context"
// Priority represents the importance of a request.
type Priority int
const (
// PriorityLow is for non-critical, background, or asynchronous tasks.
PriorityLow Priority = iota
// PriorityStandard is the default priority for most requests.
PriorityStandard
// PriorityCritical is for high-priority, user-facing, or essential tasks.
PriorityCritical
)
type priorityKey struct{}
// WithPriority attaches a Priority to the context.
func WithPriority(ctx context.Context, p Priority) context.Context {
return context.WithValue(ctx, priorityKey{}, p)
}
// GetPriority retrieves the Priority from the context.
// Returns PriorityStandard if no priority is found.
func GetPriority(ctx context.Context) Priority {
if p, ok := ctx.Value(priorityKey{}).(Priority); ok {
return p
}
return PriorityStandard
}