|
|
|
|
|
by impostervt
3398 days ago
|
|
What do people actually use Web Workers for? The examples I've seen, including this one, seem contrived.
I keep hoping they'll change it to allow background image manipulation, but I haven't seen much real progress in that front. |
|
Paint the image to a canvas, then grab the imagedata off of it, split it into as many parts as you have threads, then use the "transferrableObjects" property of postMessage to zero-copy transfer the data to each worker to be processed, transferred back, and re-stitched together.
It's pretty powerful and suprisingly easy to work with once you understand it.
[0] is a snippet from the code, but be gentile... It was a personal project where I was trying out polymer 0.5 and made a lot of questionable design choices...
Also, I've heard of the idea of using webworkers as a "first class" platform. That is do all of the core parts of your application in them and only use the "main" thread as a "ui" thread. I haven't gotten a chance to try it out, but it seems like a great idea that could really work well in some SPAs.
[0] https://github.com/Klathmon/stitchpics/blob/master/app/eleme...