How to do heavy computing in an AngularJS application?

I am writing an application using JavaScript, HTML5 and AngularJS. It should work only in fairly recent browsers (e.g. IE10, but not in IE9).

In several places of the application, intensive calculations will be performed, such as XML parsing, base64 decoding; they may include fairly large data (possibly a few MB).

If I just name things like atob() or DOMParser.parseFromString() , I get an unresponsive browser for a few seconds or even minutes. This is clearly unacceptable to the user.

I used the Angular Q service to make access to the external web service asynchronous, and therefore avoid the browser freezing while waiting for a response. But such operations already have an asynchronous API.

What about these intentional tasks that do not have an asynchronous API?

I can break down a few of these tasks, chain promises. Does it help at all? Does the browser message queue specify a queue at the end of each task?

I see the existence of "Web Workers" that seem to offer the correct multithreading. But they seem to have rather poor ability to transfer objects to / from workflows. Of course, it seems that for someone like me, I'm from C # .Net! For example, I would like to add Angular services (built-in and my own) to tasks in threads. And I do not want to copy massive data between threads.

Are other people effective web client applications that involve serious computing? If so, what do they use to achieve this?

+6
source share
1 answer

It looks like you are looking for Parallel.js library .

Here is a brief description of the library from your site:

"Parallel.js is a tiny library for multicore processing in Javascript. It was created to make full use of the APIs for web users.

Currently I don't know any examples related to using Parallel.js in Angular, but I'm sure it would be difficult to integrate the library as an Angular service.

+3
source

Source: https://habr.com/ru/post/950639/


All Articles