web-worker

Web Workers - do they create actual threads?

南笙酒味 提交于 2019-12-05 02:36:05
I have always thought that web workers create separate threads, but today I ran into the spec on w3c website. Below is a citation about web workers: This allows for thread-like operation with message-passing as the coordination mechanism. The question is - if it is thread-like , not actual thread what is an advantage(performance wise) of using this technology? Any help will be appreciated! Yes, web workers create actual threads (or processes, the spec is flexible on this). According to the Web Workers specification, when a worker is created the first step is: Create a separate parallel

How to call shared worker from the web worker?

点点圈 提交于 2019-12-05 02:34:43
问题 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. 回答1: 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

Webworker-threads: is it OK to use “require” inside worker?

偶尔善良 提交于 2019-12-05 01:44:15
(Using Sails.js) I am testing webworker-threads ( https://www.npmjs.com/package/webworker-threads ) for long running processes on Node and the following example looks good: var Worker = require('webworker-threads').Worker; var fibo = new Worker(function() { function fibo (n) { return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1; } this.onmessage = function (event) { try{ postMessage(fibo(event.data)); }catch (e){ console.log(e); } } }); fibo.onmessage = function (event) { //my return callback }; fibo.postMessage(40); But as soon as I add any code to query Mongodb, it throws an exception: (not using

Chrome not loading latest version of web worker script (runs a cached version)

人盡茶涼 提交于 2019-12-05 01:24:02
If I edit my web worker script and refresh the page, the web worker script is a cached version. I am reasonably confident it is not my webserver, because I can immediately load the latest copies of all other files, and even restarting the webserver does not fix the problem. It only loads the newest version of the web worker script if I reboot chrome, which is highly inefficient, needless to say! It doesn't fix it even if I restart chrome. Is there anything I can do to get around this? Your web server determines how cachable a given web resource is and the browser attempts to respect those

Web Workers - How To Import Modules

落爺英雄遲暮 提交于 2019-12-04 22:20:53
I am using ES2015 Import / Export modules. In my worker file, when I try to import functions like I normally do: worker.js import { a, b, c } from "./abc.js"; I get the error: SyntaxError: import declarations may only appear at top level of a module As I am exporting functions in my module 'abc.js', I am not sure how to use them using the old (& apparently on its way out) syntax: self.importScripts( "/app/abc.js" ); So, my question is, how do we use the new import module syntax with workers? Second question is, what does importScripts import into when it imports from a module in where is there

RequireJS in web worker

大憨熊 提交于 2019-12-04 19:17:33
问题 I am trying to use RequireJS inside a web worker. The problem is that I keep getting the following error when using it. Uncaught Error: importScripts failed for underscore at ./lib/underscore.js I have tested my configuration options, and they only cause this error when importing Underscore. Here they are: { baseUrl: './', paths: { jquery: 'lib/jquery', underscore: 'lib/underscore' }, shim: { underscore: { exports: '_' } } } I can add more info if necessary. The source for this project is on

BreezeJs with dedicated web worker

大兔子大兔子 提交于 2019-12-04 19:09:00
I am trying to initialize a Breeze manager inside a 'Web Worker'. RequireJs, knockout, q, breeze are being imported inside the worker. After a call to: EntityQuery.from('name').using(manager).execute() , the following error appears: Uncaught Error: Q is undefined. Are you missing Q.js? See https://github.com/kriskowal/q . A live preview is uploaded here http://plnkr.co/edit/meXjKa?p=preview (plunk supports downloading for easier debug). EDIT -- relevant code Worker.js importScripts('knockout.js', 'q.js', 'breeze.js', 'require.js'); define('jquery', function () { return jQuery; }); define(

Angular4 Web Worker application not displaying

无人久伴 提交于 2019-12-04 17:52:16
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 so I removed them. Basically I have no error right now and the page simply doesn't display: I assume it

Service Workers not updating

自古美人都是妖i 提交于 2019-12-04 16:28:12
问题 I have a service worker installed in my website, everything works fine, except when I push an update to the cached files, in fact; they stay catched forever and I seem to be unable to invalidate the cache unless I unsubscribe the worker from the `chrome://serviceworker-internals/ const STATIC_CACHE_NAME = 'static-cache-v1'; const APP_CACHE_NAME = 'app-cache-#VERSION'; const CACHE_APP = [ '/', '/app/app.js' ] const CACHE_STATIC = [ 'https://fonts.googleapis.com/css?family=Roboto:400,300,500

Synchronously Wait for Message in Web-Worker

人盡茶涼 提交于 2019-12-04 16:26:45
问题 Is there some way to synchronously wait for or check for a new message in a web-worker? I have a large complicated body of code (compiled LLVM from emscripten) that I cannot refactor around callbacks. I need to make sure that code after a certain line doesn't execute until I receive and handle a message from the UI-thread. If I block with a while-loop, the event-loop never runs so I can't receive messages. 回答1: No, unfortunately. There was some discussion of adding a way to block on a message