Skip to content

Commit

Permalink
Dirty fix threads
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaneo committed Aug 20, 2023
1 parent 1c9b211 commit 22b861c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ui/sources/services/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class Parallel {
: this.#buffers.pop().fill(0);

const message = { name, args: [sab, ...args] };
const transfer = args.filter(x => x.constructor.name == 'MessagePort');
const transfer = args.filter(arg => arg && arg.constructor.name == 'MessagePort');
this.#worker.postMessage(message, transfer);

if (sync)
Expand Down
13 changes: 5 additions & 8 deletions ui/sources/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ class Core {
*/
async init(memory, path, port, origin, start_arg) {
const fs = new Parallel(Filesystem, true);
this.#wasi = new WASI(memory, fs.link(port), {
[path]: await Filesystem.open(path, false),
});
const preopens = path ? { [path]: await Filesystem.open(path, false) } : {};
this.#wasi = new WASI(memory, fs.link(port), preopens);

const source = await WebAssembly.instantiateStreaming(fetch(`${origin}/modules/lib${this.#name}.wasm`), {
env: { memory },
Expand All @@ -119,13 +118,11 @@ class Core {
const parallel = new Parallel(Interop, false);
this.#threads.push(parallel);

const start = async () => {
(async () => {
const script = await (await fetch(`${origin}/worker.js`)).text();
const core = await parallel.create(name, script);
await core.init(memory, path, await fs.open(), origin, start_arg);
}

start();
await core.init(memory, null, await fs.open(), origin, start_arg);
})()

return id;
}},
Expand Down

0 comments on commit 22b861c

Please sign in to comment.