Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Nov 26, 2024
1 parent 9250a35 commit c1e65ac
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,45 @@ module.exports = class Core {
s._monitorIndex = this.monitors.push(s) - 1
}

// mostly for internal use when you know what you are doing!
// some caveats: does not work with preload etc nor does it work exclusive sessions
async moveFrom (core) {
await core.state.mutex.lock()

const named = new Map()

for (const s of this.sessionStates) {
if (s.name) named.set(s.name, s)
}

for (let i = 0; i < core.sessionStates.length; i++) {
const s = core.sessionStates[i]

for (let j = 0; j < s.sessions.length; j++) {
const session = s.sessions[i]
session.core = this

if (!s.isSnapshot()) {
const state = s.name ? named.get(s.name) : this.state
if (!state) throw new Error('Unknown state: ' + s.name)

session.state.removeSession(session)
session.state = state
state.addSession(session)
} else {
// TODO: move state over
}

if (session._monitorIndex >= 0) {
core.removeMonitor(session)
this.addMonitor(session)
}
}
}

await core.state.mutex.unlock()
}

removeMonitor (s) {
if (s._monitorIndex < 0) return
const head = this.monitors.pop()
Expand Down

0 comments on commit c1e65ac

Please sign in to comment.