Rework fallback for postMessage issue

Now initialise all workers with module+memory separately, and then instead of using postMessage to send thread pointers, push them into a crossbeam-deque on the Rust side.

Rayon already depends on crossbeam-dequeue, so we're not even adding another dependency, and this model allows us to push "tasks" (thread pointers) on the main thread and pop them on worker threads in arbitrary order without sacrificing correctness.
This commit is contained in:
Ingvar Stepanyan
2020-04-27 23:18:42 +01:00
parent 8d991a256e
commit 6db70e5e27
12 changed files with 255 additions and 252 deletions

View File

@@ -1,8 +1,7 @@
import initOxiPNG, { start_worker_thread } from './pkg/squoosh_oxipng.js';
addEventListener('message', async ({ data: [module, memory, threadPtr] }) => {
// console.log([module, memory, threadPtr]);
addEventListener('message', async ({ data: [module, memory] }) => {
postMessage(null);
await initOxiPNG(module, memory);
// console.log('Starting', threadPtr);
start_worker_thread(threadPtr);
start_worker_thread();
}, { once: true });