How can I handle a really slow DOM operation so it doesn't block?

Viewed 63

I have to execute a really slow (20 secs+) operation that involves the DOM. Specifically, a paper.js SVG export:

project.exportSVG({ asString: true, matchShapes: true, precision: 2 })

which repeatedly calls document.createElementNS (see here).

Since DOM operations aren't possible in workers, I can't use them to run this.

I tried using promises like this:

(new Promise((resolve, reject) => {
   console.time('export')
   var p = project;
    resolve(p.exportSVG({ asString: true, matchShapes: true, precision: 2 }));
   console.timeEnd('export')
})).then(svg => { console.log(svg) })

but it still blocks for ages.

Is there any other way I can run this without blocking for a long time?

0 Answers
Related