web-worker

Node.js and CPU intensive requests

一世执手 提交于 2019-11-27 16:33:46
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 post. However, if I want to write very CPU intensive code (in the admin back end for example) that

Using Web Workers for drawing using native canvas functions

*爱你&永不变心* 提交于 2019-11-27 12:48:56
问题 It's possible to send a CanvasPixelArray obtained via getImageData to a worker script, and let the worker script manipulate the pixels in its background thread, and eventually post the manipulated pixel array back. However, I'm using native canvas drawing functions, like drawImage . The drawImage calls are currently blocking the UI thread. This causes slow redraw of buttons, and a noticeable delay when clicking on a button, just to name a few drawbacks. (Edit: A small improvement can now be

JavaScript multithreading

烂漫一生 提交于 2019-11-27 12:03:49
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 workers I read related questions and found several variations of the above methods, but most of those

AngularJS and web workers

梦想的初衷 提交于 2019-11-27 10:08:28
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 implementation that queries against a server or even one that does this action in the same thread. Since I'm new

createImageBitmap alternative on Safari

泪湿孤枕 提交于 2019-11-27 09:21:56
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 uses that ImageBitmap as an argument to CanvasRenderingContext2D.drawImage . Things work nicely in

Since JavaScript is single-threaded, how are web workers in HTML5 doing multi-threading?

旧时模样 提交于 2019-11-27 05:16:19
问题 I've been reading about web workers in HTML5, but I know JavaScript is single-threaded. My question is: How are web workers doing multi-threaded work then? or how are they simulating it if it's not truely multi-threaded? Doesn't seem clear to me here. 回答1: As several comments have already pointed out, Workers really are multi-threaded. Some points which may help clarify your thinking: JavaScript is a language, it doesn't define a threading model, it's not necessarily single threaded Most

HTML Web Worker and Jquery Ajax call

ぐ巨炮叔叔 提交于 2019-11-27 04:21:30
I'm wondering if I can use jQuery inside the web worker file. Google Chrome gives me this error: "Uncaught ReferenceError: $ is not defined". Here is the code: The parent file: var loader = new Worker(BASE_URL + "js/rss_loader_worker.js"); // Ask the worker to start loading the RSS from the server loader.postMessage("loadRss"); // When receive the response from the server loader.onmessage = function (event) { console.log(event.data); } The worker file: onmessage = function (event) { if (event.data === "loadRss") { loadRss(); } } /** * This function handles the AJAX request to the server side *

Do Shared Web Workers persist across a single page reload, link navigation

不想你离开。 提交于 2019-11-27 04:05:57
问题 Shared Web Workers are designed to allow multiple pages from the same site (origin) to share a single Web Worker. However, it's not clear to me from the spec (or other tutorials and information on Shared Workers) whether the Shared Worker will persist if you have only one window/tab from the site and you navigate to another page on the same site. This would be most useful in the case of a WebSocket connection from the Shared Worker that stays connected as the site is navigated. For example,

Is there a way to create out of DOM elements in Web Worker?

隐身守侯 提交于 2019-11-27 03:49:27
Context: I have a web application that processes and shows huge log files. They're usually only about 100k lines long, but it can be up to 4 million lines or more. To be able to scroll through that log file (both user initiated and via JavaScript) and filter the lines with decent performance I create a DOM element for each line as soon as the data arrives (in JSON via ajax). I found this better for performance then constructing the HTML at the back-end. Afterwards I save the elements in an array and I only show the lines that are visible. For max 100k lines this takes only about a few seconds,

web worker console.log

北慕城南 提交于 2019-11-27 03:43:07
问题 Is it just me, or is console.log() too much to ask for from HTML5 web workers? I know that manipulating the DOM is blocked because it is potentially dangerous, but is there really any possibility that console.log() could be maliciously exploited by a multithreaded worker? 回答1: Agreed things would be a lot nicer, but it's not too hard to hack up a primitive console.log using postMessage . David Flanagan has a nice wrapper here. 回答2: Just wanted to post that console.log is now possible atleast