Skip to content

Commit

Permalink
Modify session cache to handle findOrStartSession correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Jul 30, 2023
1 parent a35df72 commit fb5ad51
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/sessions/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class CachedSession {
ports: OpenPort[] = []

id?: string
cacheID?: string
session: Session

/**
Expand Down Expand Up @@ -54,15 +55,20 @@ export class CachedSession {
})
}

async init() {
/**
* @param customCacheID If you want to use a custom cache ID instead of the default one
*/
async init(customCacheID?: string) {
await this.session.open()

const url = this.session.getHostname()
if (!url) throw new Error('Cannot start session')
console.log('Opened session', url)

const [id] = url.split('.')
this.id = id
sessionCache.set(id, this)
this.cacheID = customCacheID || id
sessionCache.set(this.cacheID, this)

return this
}
Expand Down Expand Up @@ -108,7 +114,7 @@ export class CachedSession {
return CachedSession.findSession(sessionID)
} catch {
const cachedSession = new CachedSession(envID)
await cachedSession.init()
await cachedSession.init(sessionID)
return cachedSession
}
}
Expand Down

0 comments on commit fb5ad51

Please sign in to comment.