web-worker

How to bubble a web worker error in a promise via worker.onerror?

烈酒焚心 提交于 2020-05-11 07:57:56
问题 I'm dealing with a web worker that needs to report back if an error has occured. Normally, I can use worker.onerror to listen to any errors that were thrown from the worker. However, when the error happens in a promise in the web worker, I can't figure out how to bubble the error back up to worker.onerror . Excuse the odd code snippet, as this seems to be the only way to demonstrate worker behavior. (The worker is defined in the HTML section). function getInlineJS() { var js = document

How to bubble a web worker error in a promise via worker.onerror?

痴心易碎 提交于 2020-05-11 07:57:31
问题 I'm dealing with a web worker that needs to report back if an error has occured. Normally, I can use worker.onerror to listen to any errors that were thrown from the worker. However, when the error happens in a promise in the web worker, I can't figure out how to bubble the error back up to worker.onerror . Excuse the odd code snippet, as this seems to be the only way to demonstrate worker behavior. (The worker is defined in the HTML section). function getInlineJS() { var js = document

waiting for web worker making http call to finish

时光总嘲笑我的痴心妄想 提交于 2020-04-30 06:39:54
问题 I'm creating multiple web workers making http calls. I have to limit the number of web workers and so I'm trying to wait for some of the workers to finish. here's an example of what I thought might work using Promises: anArray.map(async contact => { await new Promise((res, rej) => { const worker = new Worker('./http.worker', { type: 'module' }); worker.onmessage = () => { res(); }; worker.postMessage(contact); }); }); I thought this would wait for each promise to resolve before moving on to

Cross Domain Web Worker?

天涯浪子 提交于 2020-04-07 17:59:57
问题 I have https://domain1.com (domain1) and https://domain2.com (domain2). Domain2 serves a page containing javascript with a header "Access-Control-Allow-Origin: *" Domain1 runs some javascript code that invokes: new Worker("//domain2.com/script.js") Browsers throw security exceptions. Since starting writing this question, I have got around this problem by ajaxing the script, blobbing it and running it from that, but am I missing something in the original idea? 回答1: I also have the same problem

Cross Domain Web Worker?

风格不统一 提交于 2020-04-07 17:59:53
问题 I have https://domain1.com (domain1) and https://domain2.com (domain2). Domain2 serves a page containing javascript with a header "Access-Control-Allow-Origin: *" Domain1 runs some javascript code that invokes: new Worker("//domain2.com/script.js") Browsers throw security exceptions. Since starting writing this question, I have got around this problem by ajaxing the script, blobbing it and running it from that, but am I missing something in the original idea? 回答1: I also have the same problem

Cross Domain Web Worker?

别来无恙 提交于 2020-04-07 17:59:50
问题 I have https://domain1.com (domain1) and https://domain2.com (domain2). Domain2 serves a page containing javascript with a header "Access-Control-Allow-Origin: *" Domain1 runs some javascript code that invokes: new Worker("//domain2.com/script.js") Browsers throw security exceptions. Since starting writing this question, I have got around this problem by ajaxing the script, blobbing it and running it from that, but am I missing something in the original idea? 回答1: I also have the same problem

Cross Domain Web Worker?

℡╲_俬逩灬. 提交于 2020-04-07 17:59:05
问题 I have https://domain1.com (domain1) and https://domain2.com (domain2). Domain2 serves a page containing javascript with a header "Access-Control-Allow-Origin: *" Domain1 runs some javascript code that invokes: new Worker("//domain2.com/script.js") Browsers throw security exceptions. Since starting writing this question, I have got around this problem by ajaxing the script, blobbing it and running it from that, but am I missing something in the original idea? 回答1: I also have the same problem

Decode images in web worker

馋奶兔 提交于 2020-03-23 08:19:07
问题 In our WebGL application I'm trying to load and decode texture images in a web worker in order to avoid rendering hick-ups in the main thread. Using createImageBitmap in the worker and transferring the image bitmap back to the main thread works well, but in Chrome this will use three or more (maybe depending on number of cores?) separate workers (ThreadPoolForegroundWorker) which together with the main thread and my own worker will result in five threads. I'm guessing this causes my remaining

Importing node modules to web worker in React/Webpack app

北战南征 提交于 2020-02-23 06:08:32
问题 I have a React app bundled with Webpack. I would like to use a web worker for one of my components, which exports data to Pdf. The generation of the pdf can take a while and lock the browser, so I want to do this work in a web worker to do it in a separate thread. The problem I am having is importing the JsPDF library into my web worker script so i can use it. This is my worker script: import * as JsPDF from "jspdf"; export default () => { self.addEventListener("message", event => { const

Web worker Integration

孤者浪人 提交于 2020-02-06 07:37:09
问题 I want to use web worker to handle my zipcode checker function, I haven't worked with web worker before so the concept is new to me This is my zipcode function `` function checkZipCode() { event.preventDefault(); if(document.getElementById('zipcode').value < 20000) { document.getElementById('zip-result').innerHTML = 'Sorry, we haven’t expanded to that area yet'; } else if (document.getElementById('zipcode').value >= 20000) { document.getElementById('zip-result').innerHTML = 'We’ve got your