web-worker

Web workers - How do they work?

只谈情不闲聊 提交于 2019-12-04 03:19:57
问题 I'm trying to understand this example: HTML (main code): <html> <title>Test threads fibonacci</title> <body> <div id="result"></div> <script language="javascript"> var worker = new Worker("fibonacci.js"); worker.onmessage = function(event) { document.getElementById("result").textContent = event.data; dump("Got: " + event.data + "\n"); }; worker.onerror = function(error) { dump("Worker error: " + error.message + "\n"); throw error; }; worker.postMessage("5"); </script> </body> </html>

Sharing variables between web workers? [global variables?]

六眼飞鱼酱① 提交于 2019-12-04 03:01:37
问题 Is there any way for me to share a variable between two web workers? (Web workers are basically threads in Javascript) In languages like c# you have: public static string message = ""; static void Main() { message = "asdf"; new Thread(mythread).Run(); } public static void mythread() { Console.WriteLine(message); //outputs "asdf" } I know thats a bad example, but in my Javascript application, I have a thread doing heavy computations that can be spread across multiple threads [since I have a

WebWorkers in GWT Elemental

こ雲淡風輕ζ 提交于 2019-12-04 02:03:38
Workers JSNI at GWT svn It looks like WebWorkers have not been fully implemented yet. I know that elemental is in early stage of development but might be someone already have tried to make it works? The problem with web workers is that they don't really fit the standard GWT/Java model - in my opinion they barely fit the standard JS model. Web workers work by passing data back and forth between what are essentially different JavaScript VMs. That data must be in the form of a string, and each worker has to load its JS separately. This means that no variables declared in one worker (or the main

Javascript code for making my browser slow down

久未见 提交于 2019-12-04 01:12:07
I'm writing a library for WebWorkers, and I want to test the difference between running a script in the main page thread, versus in one or more workers. The problem is: I can't find out of hand a short function which will strain my browser enough that I can observe the difference. A quick search didn't return much, but it might just be that I don't really know what to search for; usually I try to optimise my code, not make it slower... I'm looking for algorithms or patterns that can be easily implemented in pure Javascript, that do not depend on the DOM or XHR, and which can have an argument

EXC_BAD_ACCESS (SIGSEGV) in WebCore::UserGestureIndicator::processingUserGesture

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 22:29:38
I have an iOS application built using a UIWebView and HTML5 websockets. The app experiences seemingly random crashes. It has occurred while a user is interacting with it and during longevity tests where no interaction between user and app occurs. The crash logs all have the following: Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000 and the thread logs contain: Thread XX name: WebCore: Worker Thread XX Crashed: 0 WebCore 0x36c8c7a0 WebCore::UserGestureIndicator::processingUserGesture() + 20 1 WebCore 0x36d7070a WebCore::DOMTimer::DOMTimer(WebCore:

Web workers inside promise causing crash

别来无恙 提交于 2019-12-03 22:02:19
The expected workflow of my code is getting the data from getData . getData calls the worker that will do ImageUtil.getHex on the input. ImageUtil.getHex is a heavy function that needs to iterate every pixel of an image area area , so that's why I want to create it runs in the background and done in multithreading. The function is also independent, which I guess is a good candidate to put in the worker. This is the chunk of code that needs the getData function: class Mosaic { // ... build() { for (let y = 0; y < canvas.height; y += options.tileHeight) { for (let x = 0; x < canvas.width; x +=

XMLHttpRequest to webservice not working in web worker

删除回忆录丶 提交于 2019-12-03 21:45:25
The code below runs perfectly if called from main javascript, but it does not run in the web worker. function getSpecData(detailLvl, startWeek, endWeek, mkt) { var params = { "detailLvl": detailLvl, "startWeek": startWeek, "endWeek": endWeek, "mkt": mkt }; var xhr; var url = "WebServices/wsSProgress.asmx/GetSpecProgressTable"; try { xhr = new XMLHttpRequest(); xhr.open('POST', url, false); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { var result = JSON.parse(xhr.responseText); $('#specProgTbl')

How to call shared worker from the web worker?

走远了吗. 提交于 2019-12-03 17:07:47
Is it possible to call a Shared Worker from the Web Worker? Could you please give me an example. In my case I have a few web workers and I need to share a singleton service between them. The SharedWorker constructor is not currently available within the WorkerGlobalScope , so you will not be able to construct an instance like you would in an iframe or window. What you can do is, create a MessageChannel for each of your workers, and use it to communicate between the worker and sharedWorker. Though doing this would negate the need for an actual SharedWorker , since you could just as well use a

Using importsScripts within Blob in a karma environment

和自甴很熟 提交于 2019-12-03 16:19:11
问题 I am working on a small project of mine using karma, and jasmine. My targeted browser is chrome 32. I am trying to import scripts within a web worker whom I have instanciated through a blob as follows : describeAsyncAppliPersephone("When the application project to DOM", function() { it("it should call the function of DomProjection in the project associated with its event", function() { var eventSentBack = { eventType: 'testReceived', headers: { id: 14, version: 4 }, payLoad: { textChanged:

How to pass functions to JavaScript Web Worker

强颜欢笑 提交于 2019-12-03 16:17:09
问题 I would like to pass a function (or functions) via a postMessage() to a web worker, because I can't refer to regular files. To kick the web worker off, I am passing an object URL (created from a Blob) to the Worker constructor. Then I am passing a message, but so far no luck putting a function in the message. The (JSON) message cannot contain functions directly (as stipulated here), and although importScripts is theoretically allowed, I have not had any success using it so far in Chrome or