Skip to content

Commit

Permalink
crocochrome: add Session method to return a single session by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiamoe committed Jul 23, 2024
1 parent 3a1227e commit ab4a94a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crocochrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,20 @@ func New(logger *slog.Logger, opts Options) *Supervisor {
}
}

// List returns a list of active session IDs.
// Session returns an existing session with the given ID. If the session does not exist, either because it has expired
// or because it has not been created, Session returns nil.
func (s *Supervisor) Session(id string) *SessionInfo {
s.sessionsMtx.Lock()
defer s.sessionsMtx.Unlock()

if sess := s.sessions[id]; sess != nil {
return sess.info
}

return nil
}

// Sessions returns a list of active session IDs.
// Crocochrome is currently wired to allow only one session at a time, by means of terminating all others when a new one
// is created, but the design of its API try to be agnostic to this decision.
func (s *Supervisor) Sessions() []string {
Expand Down

0 comments on commit ab4a94a

Please sign in to comment.