web-worker

Running JS in a killable 'thread'; detecting and canceling long-running processes

北城余情 提交于 2019-12-08 02:09:35
问题 Summary : How can I execute a JavaScript function, but then "execute" (kill) it if it does not finish with a timeframe (e.g. 2 seconds)? Details I'm writing a web application for interactively writing and testing PEG grammars. Unfortunately, the JavaScript library I'm using for parsing using a PEG has a 'bug' where certain poorly-written or unfinished grammars cause infinite execution (not even detected by some browsers). You can be happily typing along, working on your grammar, when suddenly

Shared worker do share variables

拈花ヽ惹草 提交于 2019-12-08 01:12:43
问题 I've been reading some documents about shared worker context. Lots of them point out shared worker do not share variables, which means they can not use each other variables. However, my experiment againsts that. Parent worker var port = new SharedWorker('worker.js').port; port.start(); port.postMessage('Hello'); Worker var ports = []; onconnect = function(e){ var port = e.ports[0]; port.start(); ports.push(port); console.log('Number of tabs: '+ports.length); }; ports.length keeps increasing

Getting error after adding web worker with cli command in Angular 8

随声附和 提交于 2019-12-07 22:42:55
问题 Angular 8 has added a better support for web workers. I had no luck to get it working. Does someone know what am i doing wrong? Here is official guide i followed. With this cli command i generated web worker: ng generate webWorker my-worker cli has generated my-worker.worker.ts file and tsconfig.worker.json file, and updated following files: angular.json, tsconfig.app.json. After this im getting following error: ERROR in node_modules/typescript/lib/lib.dom.d.ts(25,1): error TS6200:

Javascript: How to write a function that will be executed asynchronously?

余生颓废 提交于 2019-12-07 10:37:29
问题 I have a few lines of code that I want to run asynchronously in Javascript so that it doesn't slow down my main algorithm. See this pseudo code: //main algorithm with critical code that should run as soon as possible ... ... runInParallel(function(){ //time consuming unimportant code to shows some progress feedback to user ... } //the rest of the time critical algorithm ... ... runInParallel(function(){ //time consuming unimportant code to shows some progress feedback to user ... } //and so

Unit test code of web worker

安稳与你 提交于 2019-12-07 07:16:39
问题 Taking the example code from https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/basic_usage , the following is run by a web worker // in worker.js onmessage = function(e) { console.log('Message received from main script'); var workerResult = 'Result: ' + (e.data[0] * e.data[1]); console.log('Posting message back to main script'); postMessage(workerResult); } run by code in an Angular service/factory var myWorker = new Worker("worker.js"); I would like to be able to unit test the

WebWorkers and WebSockets with Firefox

限于喜欢 提交于 2019-12-07 06:41:13
问题 I'm trying to implement a working WebSocket connection within a WebWorker. That should be simple and it is if I use Chrome as b rowser. However, since this experiment should further become part of a production I need it to work on all the great Browsers, namely also Firefox. My problem is that I can't get it working with Firefox. At first Firefox wasn't able to create a WebWorker. That was a Bug and is fixed with version 9. But now it seems that it wouldn't be able to create a WebSocket

Using webworker and IndexedDB for loader of Three js

寵の児 提交于 2019-12-07 05:09:46
问题 I want to use dracoLoader of threeJS in multi-threads, then I selected Webworker and IndexedDB. I have gotten the correct Geometry in webworker, however, when I pass data to main thread using IndexedDB, the geometry will be changed to a normal JS object instead of a ThreeJS Geometry. The geometry lost its functions and some information. webworker.js self.saveDrcToIndexedDB = function (drcfinal) { var db; var request = indexedDB.open("drcDB"); drcfinal.indexName = self.randomStr(); request

How to pass custom class instances through Web-Workers?

狂风中的少年 提交于 2019-12-07 03:04:11
问题 Since Web-Worker JSON serialize data between threads, something like this doesn't work: worker.js function Animal() {} Animal.prototype.foobar = function() {} self.onmessage = function(e) { self.postMessage({animal: new Animal()}) } main.js let worker = new Worker('worker.js') worker.onmessage = function(e) { console.log(e.data) } worker.postMessage('go!') The outcome would be a simple object with the loss of the foobar prototype method. Is it possible to transfer the custom object back to

Debugging and profiling web workers

时光毁灭记忆、已成空白 提交于 2019-12-07 00:42:16
问题 I am running computations e.g. path-finding in web workers. This can take several seconds and I want to optimise it. Chrome seems to be about 3x faster for my current code, but where the time is spent or why I have no insight into. Generally, how can you debug web workers? How can you profile web workers? (Firefox and Chrome) 回答1: In Chrome you may open web worker source in Sources > Workers and get full interface to prifile. Profiling in Firefox - no idea. And http://www.nczonline.net/blog

Angular4 Web Worker application not displaying

瘦欲@ 提交于 2019-12-06 12:06:52
问题 I have a website that is heavy on CPU usage that I decide to port to web workers. I have followed this step by step tutorial: https://medium.com/@enriqueoriol/angular-with-web-workers-step-by-step-dc11d5872135 I have cloned this rep and made it seem identical: https://github.com/kaikcreator/angular-cli-web-worker I encountered a few issues where the document was not defined or the window. In these cases I tested on the github rep if its a problem with or with the module and it was the module