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
committed by Ingvar Stepanyan
parent 4c658b79ef
commit 0747d2c419
12 changed files with 253 additions and 255 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 });