mattslocum / ng-webworker

ng-webworker creates dynamic webworkers so angular apps can be multi-threaded.
MIT License
212 stars 31 forks source link

postmessage after running the webworker #23

Open agaurav opened 8 years ago

agaurav commented 8 years ago

Is there a way to send a message to the webworker once it has been run, like the postmessage call for the vanilla worker. In the source I see only run, stop & terminate methods in its prototype.

mattslocum commented 8 years ago

I was wondering if that would be a feature that people would want, but it didn't fit in my original goal. I wanted to simply take a cpu expensive function and convert it dynamically to a web worker, and make it behave as a promise (see the slow blur on the demo page).

Honestly, my original, personal use-case was to process a 100,000+ line csv file using the HTML5 file api. The goal was to make a short-lived web worker, and not a constant running thread.

agaurav commented 8 years ago

I am planning to use a worker to run a websocket which does some post-processing on the incoming data stream before handing it over to the angular service with notify. The need for a postmessage method comes for sending the renewed jwt token once the old one has expired. Otherwise as well it will be a very helpful feature if one can change the worker configuration on the go ( with a callback handler) instead of creating a new worker.

If you want I can give a try implementing it but i don't think i will be able to do it as well & quickly as you :)