web-worker

How to prevent HTML5 Web Workers from locking up thus correctly responding to messages from parent

我们两清 提交于 2019-12-03 12:49:13
问题 I'm using web workers to do some CPU intensive work but have the requirement that the worker will respond to messages from the parent script while the worker is still processing. The worker however will not respond to messages while it is locked in a processing loop, and I have not found a way to say poll the message queue. Thus it seems like the only solution is to break processing at an interval to allow any messages in the queue to be serviced. The obvious options are to use a timer (say

RequireJS in web worker

我只是一个虾纸丫 提交于 2019-12-03 12:29:32
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 GitHub at https://github.com/isaach1000/canvas . UPDATE: Still no luck on fixing RequireJS, but I fixed

Service Workers not updating

泄露秘密 提交于 2019-12-03 11:41:55
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,700', 'https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css' ] self.addEventListener(

Difference between Javascript async functions and Web workers?

試著忘記壹切 提交于 2019-12-03 11:27:23
问题 Threading-wise, what's the difference between web workers and functions declared as async function xxx() { } ? I am aware web workers are executed on separate threads, but what about async functions? Are such functions threaded in the same way as a function executed through setInterval is, or are they subject to yet another different kind of threading? 回答1: Async functions are just syntactic sugar around Promises and they are wrappers for Callbacks . So basically, when you await something the

Synchronously Wait for Message in Web-Worker

£可爱£侵袭症+ 提交于 2019-12-03 10:30:04
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. No, unfortunately. There was some discussion of adding a way to block on a message from the parent page, but it went nowhere. I'll see if I can dig up the relevant mailing list thread. Can

Accessing IndexedDB from multiple javascript threads

守給你的承諾、 提交于 2019-12-03 07:36:40
问题 Overview: I am trying to avoid a race condition with accessing an IndexedDB from both a webpage and a web-worker. Setup: Webpage that is saving items to the local IndexedDB as the user works with the site. Whenever a user saves data to the local DB the record is marked as "Unsent". Web-worker background thread that is pulling data from the IndexedDB, sending it to the server and once the server receives it, marking the data in the IndexedDB as "Sent". Problem: Since access to the IndexedDB is

Web worker won't start in IE unless the cache is cleared

别等时光非礼了梦想. 提交于 2019-12-03 07:14:42
I'm having a really weird bug in my HTML5 script. I wrote a sharepoint app completely in OData which uses a few HTML 5 webworker to do the number crunching in the background. This works perfect on all major browsers (FF, IE10+ Chrome, ...). However, when I perform a refresh or browse to the page again. The script still works as intended on FF and Chrome, but hangs on IE. In my network view I see a request for the Worker.js file, but with a 304 NOT MODIFIED response. IE then just hangs there on that request with a status of (Pending). This issue only gets resolved when I clear my browser cache.

Degrading gracefully with Web Workers

和自甴很熟 提交于 2019-12-03 06:55:52
问题 So I'm starting to hear more and more about Web Workers. I think it's absolutely fantastic, but the question I haven't seen anyone really tackle so far is how to support older browsers that do not yet have support for the new technology. The only solution I've been able to come up with so far is to make some sort of wrapper around the web worker functionality that would fall back to some crazy timer based solution that would simulate multi-threaded execution. But even in that case, how does

Are web workers a secure way to sandbox untrusted javascript code

≯℡__Kan透↙ 提交于 2019-12-03 06:50:55
I was wondering if a web worker would be a secure way to sandbox untrusted javascript code. Let's say for example in the context of a drawing application where developers can implement new drawing tools, you could put their code inside a webworker, and any time the user clicks on the canvas, send them a JSON message containing the cursor position, and an array of image data, and when the script is done, it passes a message back containing the new image data. Would this be secure, or are there risks I'm not thinking of? asvd DOM is not available to the Web-workers, but it is possible to access

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

拥有回忆 提交于 2019-12-03 06:35:08
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.postMessage(globals.data); // Send data to our worker. }); arithmetic.js : define(["use!underscore", "use