web-worker

How to apply web worker to rendering of a PDF using makepdf

若如初见. 提交于 2019-11-29 05:16:50
I successfully created a PDF using a JavaScript plug-in ( pdfmake ) and it was great. But when I try to render an ~8,000-row inventory/ledger printout, it freeze for over a minute. This is how I usually declare my docDefinition var docDefinition = { pageOrientation: orientation, footer: function(currentPage, pageCount) { return {text: currentPage.toString() + ' / ' + pageCount, fontSize:8, alignment:'center'}; }, content:[ printHeader, { fontSize: 8, alignment: 'right', style: 'tableExample', table: { widths: width, headerRows: 1, body: arr }, layout: 'lightHorizontalLines' }] } where var

How fast are Web Worker's messages?

不问归期 提交于 2019-11-29 03:49:48
I wondered if transmission to or from a web worker can be a bottleneck. Should we post message just as we trigger any kind of events, or should we take care and try to limit as much as possible the communication between the two ? Let's have an example. If I have a huge array that is dynamically constructed (e.g. an array of contact points coming from mousemove or touchmove for a gesture recogniser), is it more efficient to transfer the data iteratively – i.e. send each element as soon as we receive it and let the worker store them on its side – or is it better to store them on the main thread

HTML5 Websocket within Webworker

↘锁芯ラ 提交于 2019-11-29 03:48:14
I've managed to get websockets working inside a webworker using Chrome, but only for receiving data. When I try to send data I get a DOM Exception, has anyone managed to send data? This is what I have for my web worker. self.addEventListener('message', function(e) { var data = e.data; switch (data.cmd) { case 'init': self.postMessage("Initialising Web Workers..."); testWS(); break; default: self.postMessage('Unknown command: ' + data.msg); }; }, false); function testWS() { var connectionAddr = "ws://localhost:8003"; var socket = new WebSocket(connectionAddr); socket.onmessage = function(event)

Run Angular 2 app in web worker using WebPack

烈酒焚心 提交于 2019-11-29 03:46:17
I'm trying to move the whole execution of an Angular 2 app to a web worker, but I've find out that all examples available right now are using System.js, and I'm trying to do so with a WebPack based project (built with angular-cli). Has anyone done this or have an idea on how to do this with WebPack? Below is my main.ts bootstrap file: import './polyfills.ts'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; if (environment.production) { enableProdMode(); } import {bootstrapWorkerUi} from '@angular/platform-webworker'; bootstrapWorkerUi('

Detect whether postMessage can send objects?

末鹿安然 提交于 2019-11-29 03:36:18
问题 I'm looking for a neat way to detect whether postMessage in the browser supports the sending and receiving of objects or just strings. I figure that someone out there must have wrote something that does this but I have not managed to find a solution. I'm using postMessage to send data to/from a WebWorker. Whilst detecting whether the browser supports workers is straight-forward, detecting whether objects can be send via postMessage has proved more difficult. I'd like to write a simple

What can I use with Web Workers?

给你一囗甜甜゛ 提交于 2019-11-29 03:10:44
I have a few questions about web workers Does the worker have access to storage? E.g. indexedDB/webSQL and local storage of the file the worker was initiated from? How can i include a file in a worker? I have a functions.js which has alot of quick app related functions and it really wont make sense to copy paste the file's contents in a worker only to have two different places up update my functions. Can I have a DOM inside a worker? like load an audio file in a temp audio tag to read its duration and if it is playable or not. Not access dom of parent page, but have a DOM in the worker itself.

Parsing XML in Web Workers

匆匆过客 提交于 2019-11-29 02:05:54
I know the Web Worker spec says "no access to DOM because DOM is not thread safe". While I can see that's logical for web workers and the HTML page DOM, it's actually very restrictive when considering parsing XML from an XmlHttpRequest call - after all, the basic handling of that call is asynchronous and so has little effect on the foreground thread, it's the parsing of the XML that slows down the foreground thread (when dealing with XML apps). Is there any way other than building my own XML parser in Javascript (I'm not going the XPCOM route!) to parse XML in the Web Worker? Martin Bartlett

Reliably detect if the script is executing in a web worker [duplicate]

别来无恙 提交于 2019-11-29 01:43:23
This question already has an answer here: Any standard mechanism for detecting if a JavaScript is executing as a WebWorker? 5 answers I am currently writing a little library in JavaScript to help me delegate to a web-worker some heavy computation . For some reasons (mainly for the ability to debug in the UI thread and then run the same code in a worker) I'd like to detect if the script is currently running in a worker or in the UI thread. I'm not a seasoned JavaScript developper and I would like to ensure that the following function will reliably detect if I'm in a worker or not : function

Web Workers handling AJAX calls - optimisation overkill?

依然范特西╮ 提交于 2019-11-29 01:29:56
问题 I'm working with a code that handles all AJAX requests using Web Workers (when available). These workers do almost nothing more than XMLHttpRequest object handling (no extra computations). All requests created by workers are asynchronous ( request.open("get",url,true) ). Recently, I got couple of issues regarding this code and I started to wonder if I should spend time fixing this or just dump the whole solution. My research so far suggests that this code may be actually hurting performance.

Any standard mechanism for detecting if a JavaScript is executing as a WebWorker?

浪尽此生 提交于 2019-11-28 23:23:45
A WebWorker executes with a scope completely separate from the 'window' context of traditional JavaScript. Is there a standard way for a script to determine if it is, itself, being executed as a WebWorker? The first 'hack' I can think of would be to detect if there is a 'window' property in the scope of the worker. If absent, this might mean we are executing as a WebWorker. Additional options would be to detect properties not present in a standard 'window' context. For Chrome 14, this list currently includes: FileReaderSync FileException WorkerLocation importScripts openDatabaseSync