Skip to content

Commit ee4e98d

Browse files
committed
chore: add context functions for passing ids
These functions were mistakenly removed, so this change just adds them back. Signed-off-by: Donnie Adams <[email protected]>
1 parent 58a71d7 commit ee4e98d

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)