web-worker

Why are web workers not allowed to modify the dom

依然范特西╮ 提交于 2019-12-11 03:21:37
问题 I know web workers work as a separate thread than the UI thread but i dont understand why they are not allowed to modify the DOM . I mean that you can allow inter thread communication and keep the DOM data in a shared space and have the web workers thread modify the DOM . Why is this not allowed in browsers? 回答1: Because the DOM is not threadsafe, and JavaScript does not expose a thread API. See also: Is JavaScript multithreaded? Thread Safety in Javascript? Using web workers - About thread

How to implement a recursive function as a Web Worker?

北慕城南 提交于 2019-12-11 02:42:26
问题 Here is a setup: A big data array to be processed in recursive function. A recursive function itself, which is running as Web Worker to avoid stack size limitations. A result processor, which is called after recursive function reached it's 'end of recursion' condition. I've checked web worker specs, but they are kinda unreadable and messy to give a simple answer on simple question. What I do not understand it's How to pass data to function (in web worker) How to get result from function and

My javascript web workers are dying silently at random places. How can I debug this?

限于喜欢 提交于 2019-12-11 02:22:48
问题 The web worker just stops, no errors or anything. The code is entirely deterministic, but it will die at different points in the code. Edit: The problem was that I was not maintaining a reference to my workers, and so they seemed to die randomly when they were garbage collected. 回答1: The problem was that I was not maintaining a reference to my workers, and so they seemed to die randomly when they were garbage collected. 回答2: I found a similar situation in Firefox where my worker seemed to be

Is it possible to optimize two scripts using web workers? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-11 01:51:16
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I'm running two libraries that are dependency aware. What I mean is the order of their execution does not matter. They will detect

Is XHR allowed within web-worker in PhoneGap/Cordova?

天大地大妈咪最大 提交于 2019-12-10 22:14:54
问题 Environment: Cordova 2.9.0, iOS (Xcode 4.6.3 iPad 6.1 Simulator and iPad 3 running iOS 6.1.3) I am trying to separate out the processing of loading another file into a web-worker. The file I am loading is part of the application (meaning it is in the same domain). The following code works fine when NOT run in a web-worker: ( url is of the form "/db/file.json") function loadXMLDoc(url, successCallback) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp

Javascript worker.postMessage shrinks empty array

主宰稳场 提交于 2019-12-10 19:21:22
问题 I am passing an empty array to a worker, which should populate the array and return it - I know there are other ways of doing this, but I'm more interested in why it isnt working, than getting it to work. The main code: var arr = new Array(4) console.log(arr.length)//outputs 4 var worker = new Worker("whatever.js") worker.postMessage(arr) The worker code self.onmessage = function(msg){ console.log(msg.data.length)//outputs 0 } If I pass in a populated array, it works. If I even set a single

Shared memory between Isolates using IndexedDB

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 17:44:01
问题 I'm working with Isolates right now and wanted to know if using IndexedDB to share data between Isolates is a good way to communicate? Specifically, I want one Isolate to be able to write to it, then tell the other Isolates they may readonly it. This is data that would be considered unchanging once it is written and is fairly large. The main reason I want to do this is because I don't want to send a 6MB Map to 3 different Isolates since it is a bit intensive on the program. 回答1: Web workers

Angular index.html with dynamic values | web-worker

孤街醉人 提交于 2019-12-10 16:17:16
问题 Until recently we used express.js to serve index.html for Angular, because we need to fill in dynamic variables from the database before the app starts. <script> window .__ envs = {{{json envs}}} </script> However, the new Angular 7 caches the source index.html through web-worker. So when I load the web, it doesn't load properly until I click on the reload. I tried to disable index.html from the webworker. Nothing happened. I tried to turn off the web-worker and remove it everywhere. Now I

setTimeout from a web worker

醉酒当歌 提交于 2019-12-10 15:59:51
问题 What if I want to put a web worker on pause if I cannot proceed processing data, and try a second later? Can I do that in this manner inside a web worker? var doStuff = function() { if( databaseBusy() ) { setTimeout(doStuff, 1000); } else { doStuffIndeed(); } } I'm getting Uncaught RangeError: Maximum call stack size exceeded and something tells me it's because of the code above. 回答1: If by "pause" you mean "further calls to worker.postMessage() will get queued up and not processed by the

How to import a library like moment.js into a web worker

。_饼干妹妹 提交于 2019-12-10 14:48:57
问题 Can I import a library installed with npm into a web worker? I need to use the moment.js library into a web worker. It is installed via npm into the node_modules/moment directory I already have tried with this at the top of the worker.js file: importScripts('/node_modules/moment/moment.js'); But I get GET http://192.168.2.1:8100/node_modules/moment/moment.js 404 (Not Found) 回答1: Yes, it's possible, chances are you're already using a popular bundler like webpack or parcel , but even if you're