fix: lazy load pixel worker
This commit is contained in:
parent
7e3e47b4ba
commit
e4b3cce517
@ -1,16 +1,18 @@
|
|||||||
const worker = new Worker("build/workers/pixel-worker.js");
|
let worker;
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
let cb = {};
|
let cb = {};
|
||||||
|
|
||||||
worker.addEventListener("message", ev => {
|
export default (msg: any): Promise<any> => new Promise((res, rej) => {
|
||||||
|
|
||||||
|
if (!worker) {
|
||||||
|
worker = new Worker("build/workers/pixel-worker.js");
|
||||||
|
worker.addEventListener("message", ev => {
|
||||||
if (ev.data.i in cb) {
|
if (ev.data.i in cb) {
|
||||||
cb[ev.data.i](ev.data.result);
|
cb[ev.data.i](ev.data.result);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default (msg: any): Promise<any> => new Promise((res, rej) => {
|
|
||||||
i++;
|
i++;
|
||||||
const _i = i;
|
const _i = i;
|
||||||
worker.postMessage({ i: _i, ...msg });
|
worker.postMessage({ i: _i, ...msg });
|
||||||
|
Loading…
Reference in New Issue
Block a user