@@ -49,9 +49,7 @@ func New(opts ...Options) (*Server, error) {
4949
5050 runnerOpts , opt := complete (opts )
5151 r , err := runner .New (append (runnerOpts , runner.Options {
52- MonitorFactory : & SessionFactory {
53- events : events ,
54- },
52+ MonitorFactory : NewSessionFactory (events ),
5553 })... )
5654 if err != nil {
5755 return nil , err
@@ -61,9 +59,7 @@ func New(opts ...Options) (*Server, error) {
6159 CacheOptions : runner.CacheOptions {
6260 Cache : new (bool ),
6361 },
64- MonitorFactory : & SessionFactory {
65- events : events ,
66- },
62+ MonitorFactory : NewSessionFactory (events ),
6763 })... )
6864 if err != nil {
6965 return nil , err
@@ -102,6 +98,14 @@ var (
10298
10399type execKey struct {}
104100
101+ func ContextWithNewID (ctx context.Context ) context.Context {
102+ return context .WithValue (ctx , execKey {}, fmt .Sprint (atomic .AddInt64 (& execID , 1 )))
103+ }
104+
105+ func IDFromContext (ctx context.Context ) string {
106+ return ctx .Value (execKey {}).(string )
107+ }
108+
105109func (s * Server ) list (rw http.ResponseWriter , req * http.Request ) {
106110 rw .Header ().Set ("Content-Type" , "application/json" )
107111 enc := json .NewEncoder (rw )
@@ -283,6 +287,12 @@ type SessionFactory struct {
283287 events * broadcaster.Broadcaster [Event ]
284288}
285289
290+ func NewSessionFactory (events * broadcaster.Broadcaster [Event ]) * SessionFactory {
291+ return & SessionFactory {
292+ events : events ,
293+ }
294+ }
295+
286296func (s SessionFactory ) Start (ctx context.Context , prg * types.Program , env []string , input string ) (runner.Monitor , error ) {
287297 id , _ := ctx .Value (execKey {}).(string )
288298
0 commit comments