forked from grafana/k6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
40 lines (33 loc) · 907 Bytes
/
context.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
28
29
30
31
32
33
34
35
36
37
38
39
40
package lib
import (
"context"
)
type ctxKey int
const (
ctxKeyExecState ctxKey = iota
ctxKeyScenario
)
// WithExecutionState embeds an ExecutionState in ctx.
func WithExecutionState(ctx context.Context, s *ExecutionState) context.Context {
return context.WithValue(ctx, ctxKeyExecState, s)
}
// GetExecutionState returns an ExecutionState from ctx.
func GetExecutionState(ctx context.Context) *ExecutionState {
v := ctx.Value(ctxKeyExecState)
if v == nil {
return nil
}
return v.(*ExecutionState)
}
// WithScenarioState embeds a ScenarioState in ctx.
func WithScenarioState(ctx context.Context, s *ScenarioState) context.Context {
return context.WithValue(ctx, ctxKeyScenario, s)
}
// GetScenarioState returns a ScenarioState from ctx.
func GetScenarioState(ctx context.Context) *ScenarioState {
v := ctx.Value(ctxKeyScenario)
if v == nil {
return nil
}
return v.(*ScenarioState)
}