Loop through Wasm re-init for issue repro

This commit is contained in:
Ingvar Stepanyan
2020-09-30 16:41:55 +01:00
parent 11ada77c30
commit 2ce1e76b72
2 changed files with 13 additions and 3 deletions

View File

@@ -54,7 +54,12 @@ async function startMainThread() {
return {
optimise,
freeWorkers: () => {
for (const worker of resolvedWorkers) {
worker.terminate();
}
},
};
}
export default startMainThread();
export default () => startMainThread();

View File

@@ -1,7 +1,12 @@
// @ts-ignore
import optimiser from '../../../codecs/oxipng';
import init from '../../../codecs/oxipng/spawn';
import { EncodeOptions } from './encoder-meta';
export async function compress(data: ArrayBuffer, options: EncodeOptions): Promise<ArrayBuffer> {
return (await optimiser).optimise(new Uint8Array(data), options.level).buffer;
for (let i = 0; i < 100; i += 1) {
const optimiser = await init();
console.log(`Run #${i}: ${optimiser.optimise(new Uint8Array(data), options.level).buffer.byteLength} bytes`);
optimiser.freeWorkers();
}
return (await init()).optimise(new Uint8Array(data), options.level).buffer;
}