web-worker

How to use Web Workers into a Module build with Requirejs?

左心房为你撑大大i 提交于 2019-12-04 11:52:03
问题 I have a well working app writing with Requirejs and Backbonejs, but it's really slowing sometimes... For example when it comes to make some arithmetic work! I tried to use a Web Worker to do this arithmetic work like this : My Module(traffic.js) : define(["jquery", "use!underscore", "use!backbone", "namespace" ], function ($, _, Backbone, globals) { ..... var worker = new Worker("arithmetic.js"); worker.addEventListener('message', function(e) { console.log(e.data); }, false); worker

Can someone explain the webworker-thread example?

随声附和 提交于 2019-12-04 11:49:42
var Worker = require('webworker-threads').Worker; require('http').createServer(function (req,res) { var fibo = new Worker(function() { function fibo (n) { return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1; } // which onmessage does this this refer to? onmessage = function (event) { //reference 1 postMessage(fibo(event.data)); } }); fibo.onmessage = function (event) { //reference 2 res.end('fib(40) = ' + event.data); }; fibo.postMessage(40); }).listen(port); This is the code found as an example for the webworker class. I was looking at the API and doen't seem to understand what reference 1 in the

Web worker file is cached and never re-loaded in IE 11

两盒软妹~` 提交于 2019-12-04 11:46:32
I am running a simple HTML5 app that works in Chrome and Firefox. It uses a web worker, as in: var worker = new Worker("the/worker/URL/Code.js"); I have experimented for over an hour in IE, and I finally found that the web worker's code is never reloaded. When I get the version that it has, to throw an error, the debugger shows me a completely outdated version of the worker code file, even though, all other files have been reloaded properly. I flushed the cache, using the standard advice found everywhere: Safety -> Delete Browsing History -> Select items -> Ok -> Wait -> Ctrl+F5 to reload ->

How do I strongly type a TypeScript web worker file with postMessage?

☆樱花仙子☆ 提交于 2019-12-04 11:20:48
I have a web worker that I want to write with TypeScript. The problem is Worker.postMessage - TypeScript assumes that every script will be loaded in the window context, and so expects Window.postMessage , which has a different syntax. This means TypeScript throws an error when I try to use postMessage . There are ways to work around this, for instance by redefining the function declare function postMessage(message: any) , but most of these are ugly kludges at best - the whole point of TS is checking types, declaring my own dummy ones defeats that. By the same token - window (and everything in

Why does web worker performance sharply decline after 30 seconds?

核能气质少年 提交于 2019-12-04 08:27:57
问题 I'm trying to improve the performance of a script when executed in a web worker. It's designed to parse large text files in the browser without crashing. Everything works pretty well, but I notice a severe difference in performance for large files when using a web worker. So I conducted a simple experiment. I ran the script on the same input twice. The first run executed the script in the main thread of the page (no web workers). Naturally, this causes the page to freeze and become

Why was HTML5 Web Workers support removed from the Android browser in versions 2.2 and up?

白昼怎懂夜的黑 提交于 2019-12-04 08:13:23
问题 I'm trying to learn something about JavaScript threading. And from a tutorial I learned about HTML5 API web worker. This API enables JavaScript multi-threading. So I start to figure out how and where can I use this feature. Form http://caniuse.com/#search=worker I find this API is only supported in lower version of Android browser. It is unavailable in Android 2.2 and later. Is this result correct?I f it is, is it because of the performance consideration? On which version will this API be

Unable to create Web Worker from inside webworker in Chrome

谁说胖子不能爱 提交于 2019-12-04 06:24:34
Using Chrome 17.0.963.46 m, I tried to create a new web worker from inside a web worker. But got a "Uncaught ReferenceError: Worker is not defined" Any info. on this? (Google throw surprisingly few links on creating web worker inside webworkers) That is the current state even on Chrome 19 - here is the bug: http://code.google.com/p/chromium/issues/detail?id=31666 It's working on FF. Creating workers within workers is not available in chrome. FF implemented this with the Example. See the link for Example and Chroem bug. https://developer.mozilla.org/en-US/docs/DOM/Worker/Functions_available_to

failed to load script - Webworker (PDF.JS)

丶灬走出姿态 提交于 2019-12-04 06:06:31
I'm trying to load the pdf.js webworker, but I can't!? The URL //cdn.localhost/js/pdf/worker_loader.js?v=280 exists when opening it in the browser error Failed to load script: //cdn.localhost/js/pdf/worker_loader.js?v=280 (nsresult = 0x805303f4) html (URL = //secure.localhost) <!DOCTYPE html> <html> <head></head> <body> <script type="text/javascript" src="//cdn.localhost/js/pdf/core.js?v=280"></script> <script type="text/javascript" src="//cdn.localhost/js/pdf/util.js?v=280"></script> <script type="text/javascript" src="//cdn.localhost/js/pdf/api.js?v=280"></script> <script type="text

Obtain data synchronously from WebWorker?

不问归期 提交于 2019-12-04 05:50:46
While I understand that JavaScript is inherently single-threaded and generally frowns upon such things, I am wondering if there is any way to get a WebWorker to wait until some data is made available from the main thread without destroying the call stack of the WebWorker. As this is for a fun project, I can use new technologies and things that won't reliably run on older browsers, and I don't mind esoteric hacks as long as they work. Some other solutions that I have thought about: Continuously poll LocalStorage in a loop until there is data at a predetermined key. This would seem to work

Posting a message to a web worker while it is still running

六月ゝ 毕业季﹏ 提交于 2019-12-04 03:27:47
问题 Say we have a web worker referring to a file called "worker.js". We use the worker to execute a function in "worker.js" that does some lengthy operation. We call post the respective message to the worker and proceed in the main thread. However, before the worker has finished doing its initial work, the main thread posts another message to it. My question: Will the worker continue with our time-taking function and only process the newly posted message once finished or will it interrupt its