@@ -49,9 +49,7 @@ func New(opts ...Options) (*Server, error) {
49
49
50
50
runnerOpts , opt := complete (opts )
51
51
r , err := runner .New (append (runnerOpts , runner.Options {
52
- MonitorFactory : & SessionFactory {
53
- events : events ,
54
- },
52
+ MonitorFactory : NewSessionFactory (events ),
55
53
})... )
56
54
if err != nil {
57
55
return nil , err
@@ -61,9 +59,7 @@ func New(opts ...Options) (*Server, error) {
61
59
CacheOptions : runner.CacheOptions {
62
60
Cache : new (bool ),
63
61
},
64
- MonitorFactory : & SessionFactory {
65
- events : events ,
66
- },
62
+ MonitorFactory : NewSessionFactory (events ),
67
63
})... )
68
64
if err != nil {
69
65
return nil , err
@@ -102,6 +98,14 @@ var (
102
98
103
99
type execKey struct {}
104
100
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
+
105
109
func (s * Server ) list (rw http.ResponseWriter , req * http.Request ) {
106
110
rw .Header ().Set ("Content-Type" , "application/json" )
107
111
enc := json .NewEncoder (rw )
@@ -283,6 +287,12 @@ type SessionFactory struct {
283
287
events * broadcaster.Broadcaster [Event ]
284
288
}
285
289
290
+ func NewSessionFactory (events * broadcaster.Broadcaster [Event ]) * SessionFactory {
291
+ return & SessionFactory {
292
+ events : events ,
293
+ }
294
+ }
295
+
286
296
func (s SessionFactory ) Start (ctx context.Context , prg * types.Program , env []string , input string ) (runner.Monitor , error ) {
287
297
id , _ := ctx .Value (execKey {}).(string )
288
298
0 commit comments