Skip to content

Commit a35a6f0

Browse files
authored
Merge pull request #235 from thedadams/add-context-funcs-back
chore: add context functions for passing ids
2 parents 58a71d7 + ee4e98d commit a35a6f0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/server/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ var (
8787

8888
type execKey struct{}
8989

90+
func ContextWithNewID(ctx context.Context) context.Context {
91+
return context.WithValue(ctx, execKey{}, fmt.Sprint(atomic.AddInt64(&execID, 1)))
92+
}
93+
94+
func IDFromContext(ctx context.Context) string {
95+
return ctx.Value(execKey{}).(string)
96+
}
97+
9098
func (s *Server) Close() {
9199
s.runner.Close()
92100
}
@@ -290,7 +298,7 @@ func NewSessionFactory(events *broadcaster.Broadcaster[Event]) *SessionFactory {
290298
}
291299

292300
func (s SessionFactory) Start(ctx context.Context, prg *types.Program, env []string, input string) (runner.Monitor, error) {
293-
id, _ := ctx.Value(execKey{}).(string)
301+
id := IDFromContext(ctx)
294302

295303
s.events.C <- Event{
296304
Event: runner.Event{

0 commit comments

Comments
 (0)