Skip to content

Commit

Permalink
Safer relaunch of cores
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaneo committed Sep 10, 2023
1 parent d32461c commit 26c2eb6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ui/sources/services/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export default class Core {
shared: true,
});

/** @type {Promise} */
static #running = Promise.resolve();

/** @type {() => void} */
static #stop = () => {};

/** @type {Parallel<Interop>} */
#parallel = null;

Expand Down Expand Up @@ -45,6 +51,9 @@ export default class Core {
* @returns {Promise<void>}
*/
async create(system, rom, canvas, on_variables) {
await Core.#running;
Core.#running = new Promise(resolve => Core.#stop = resolve);

const graphics = new Graphics(canvas);

const origin = location.origin + location.pathname.substring(0, location.pathname.lastIndexOf('/'));
Expand Down Expand Up @@ -98,11 +107,16 @@ export default class Core {
}

this.#threads.forEach(child => child.close());
this.#parallel?.close();
this.#threads = [];

this.#parallel?.close();
this.#parallel = null;

this.#interop = null;

new Uint8Array(Core.#memory.buffer).fill(0);

Core.#stop();
}

/** @param {Settings} settings @returns {Promise<void>} */
Expand Down

0 comments on commit 26c2eb6

Please sign in to comment.