Skip to content

Commit

Permalink
sort by createdTimestamp instead of insert order
Browse files Browse the repository at this point in the history
  • Loading branch information
seeM committed Nov 26, 2024
1 parent 2d5092a commit 586b7e1
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession
getConsoleSessionForRuntime(runtimeId: string): ILanguageRuntimeSession | undefined {
// It's possible that there are multiple consoles for the same runtime,
// for example, if one failed to start and is uninitialized. In that case,
// we return the last.
const session = Array.from(this._activeSessionsBySessionId.values()).reverse().find(session =>
session.session.runtimeMetadata.runtimeId === runtimeId &&
session.session.metadata.sessionMode === LanguageRuntimeSessionMode.Console &&
session.state !== RuntimeState.Exited);
// we return the most recently created.
const session = Array.from(this._activeSessionsBySessionId.values())
.sort((a, b) => b.session.metadata.createdTimestamp - a.session.metadata.createdTimestamp)
.find(session =>
session.session.runtimeMetadata.runtimeId === runtimeId &&
session.session.metadata.sessionMode === LanguageRuntimeSessionMode.Console &&
session.state !== RuntimeState.Exited);
if (session) {
return session.session;
} else {
Expand Down

0 comments on commit 586b7e1

Please sign in to comment.