Skip to content

Commit

Permalink
Make sure session IDs are always unique after restoring
Browse files Browse the repository at this point in the history
  • Loading branch information
DervexDev committed Aug 7, 2024
1 parent 14641f7 commit 8642025
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/argon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as logger from "./logger"
import * as config from "./config"
import { getCurrentDir } from "./util"

let lastId = 0

function log(data: string, silent?: boolean) {
let output = undefined

Expand Down Expand Up @@ -65,20 +67,33 @@ async function spawn(args: string[], silent?: boolean) {
: Promise.reject(firstOutput)
}

function generateId() {
let id = Date.now()

if (id === lastId) {
id++
}

lastId = id

return id
}

export async function serve(
project: string,
options: string[],
): Promise<[number, string]> {
const id = Date.now()
const id = generateId()
const message = await spawn(["serve", project, id.toString(), ...options])

return [id, message]
}

export async function build(project: string, options: string[]) {
if (options.includes("--watch")) {
const id = Date.now()
const id = generateId()
await spawn(["build", project, id.toString(), ...options])

return id
}

Expand All @@ -87,8 +102,9 @@ export async function build(project: string, options: string[]) {

export async function sourcemap(project: string, options: string[]) {
if (options.includes("--watch")) {
const id = Date.now()
const id = generateId()
await spawn(["sourcemap", project, id.toString(), ...options])

return id
}

Expand Down
3 changes: 2 additions & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export class State {
return !matches
})

this.context.workspaceState.update("lastSessions", lastSessions)
this.updateItem()

this.context.workspaceState.update("lastSessions", lastSessions)
}

public getSessions() {
Expand Down

0 comments on commit 8642025

Please sign in to comment.