web-worker

how to pass large data to web workers

血红的双手。 提交于 2019-11-26 22:38:29
问题 I am working on web workers and I am passing large amount of data to web worker, which takes a lot of time. I want to know the efficient way to send the data. I have tried the following code: var worker = new Worker('js2.js'); worker.postMessage( buffer,[ buffer]); worker.postMessage(obj,[obj.mat2]); if (buffer.byteLength) { alert('Transferables are not supported in your browser!'); } 回答1: UPDATE : According to Mozilla the SharedArrayBuffer has been disabled in all major browsers, thus the

Node.js and CPU intensive requests

拥有回忆 提交于 2019-11-26 22:27:57
问题 I've started tinkering with Node.js HTTP server and really like to write server side Javascript but something is keeping me from starting to use Node.js for my web application. I understand the whole async I/O concept but I'm somewhat concerned about the edge cases where procedural code is very CPU intensive such as image manipulation or sorting large data sets. As I understand it, the server will be very fast for simple web page requests such as viewing a listing of users or viewing a blog

How to upload files in Web Workers when FormData is not defined

删除回忆录丶 提交于 2019-11-26 20:44:01
问题 How can I retrieve $_FILES in PHP when I upload through a Web Worker? When I tried to use FormData , I got the following error: Error: FormData is not defined This is my code: function uploadFile(blobFile, fileName, filePart, totalChunks) { //if I try to put this //var formData = new FormData(); //it does not work var xhr = new XMLHttpRequest(); xhr.open("POST", "upload.php"+"?"+"file="+fileName + filePart, true); xhr.onload = function(e) {}; xhr.send(blobFile); } So in upload.php how am I

What happens to a Web Worker if I close the page that created this Web Worker?

喜欢而已 提交于 2019-11-26 20:14:03
问题 Let's say I have a page called Main.html that creates a web worker. If I close the Main page by changing window.location, would the web worker be terminated or would the web worker be still running? How does Firefox or Chrome choose to "handle long-running Worker tasks after the page has closed"? If the worker's task is to send a very quick POST request, for this case, does the browser terminate the worker immediatly after the page is closed or does the browser allow the worker to finished

AngularJS and web workers

落花浮王杯 提交于 2019-11-26 17:55:36
问题 How can angularJS use web workers to run processes in the background? Is there any pattern I should follow on doing this? Currently, I am using a service that has the model in a separate web worker. This service implements methods like: ClientsFacade.calculateDebt(client1); //Just an example.. In the implementation, this method sends a message to the worker with the data. This allows me to abstract the fact that it is being performed in a separate thread and I could also provide an

Which would be better for concurrent tasks on node.js? Fibers? Web-workers? or Threads?

一曲冷凌霜 提交于 2019-11-26 16:47:06
I stumbled over node.js sometime ago and like it a lot. But soon I found out that it lacked badly the ability to perform CPU-intensive tasks. So, I started googling and got these answers to solve the problem: Fibers, Webworkers and Threads (thread-a-gogo). Now which one to use is a confusion and one of them definitely needs to be used - afterall what's the purpose of having a server which is just good at IO and nothing else? Suggestions needed! UPDATE: I was thinking of a way off-late; just needing suggestions over it. Now, what I thought of was this: Let's have some threads (using thread_a

How to access jQuery in HTML 5 web worker

自闭症网瘾萝莉.ら 提交于 2019-11-26 16:42:30
问题 I am unable to to access jQuery inside an HTML5 web worker. Is there a way I can do that? 回答1: tl;dr: include this script before jQuery JQuery initally accesses lots of document properties to check for browser features. document is not defined in Worker and you actually cannot create Document instance in web workers at this moment. JQuery isn't prepared for that - as you could see in comments on your question, nobody seems to understand what would you do with JQuery without DOM. Since, as I

JavaScript multithreading

丶灬走出姿态 提交于 2019-11-26 15:53:19
问题 I'm working on comparison for several different methods of implementing (real or fake) multithreading in JavaScript. As far as I know only webworkers and Google Gears WorkerPool can give you real threads (ie. spread across multiple processors with real parallel execution). I've found the following methods: switch between tasks using yield() use setInterval() (or other non-blocking function) with threads waiting one for another use Google Gears WorkerPool threads (with a plugin) use html5 web

createImageBitmap alternative on Safari

Deadly 提交于 2019-11-26 14:42:30
问题 I'd like to generate images in a bit of asm.js code running on a web worker. And I'd like to regularly composite the latest state of that computation onto a user-visible 2d canvas, together with some other content. Currently I have code which constructs an ImageData object using its constructor, based on a portion of the array buffer used by the asm.js code, calls createImageBitmap to turn the ImageData into an ImageBitmap, transfers that image bitmap from the worker to the GUI thread and

Angular CLI generated app with Web Workers

别说谁变了你拦得住时间么 提交于 2019-11-26 12:37:34
问题 Reading the Angular Documentation, you can find several references to bootstrap your whole Angular app inside a Web Worker, so your UI won\'t get blocked by heavy JS usage. However, at this moment there\'s no official information on how to do that, and the only info in the Angular Doc. is that this is an experimental feature. How can I use this approach to take advantage of web workers in Angular? 回答1: For Angular 7, see answer below. I spent a lot of time to figure out how to do it, so I