web-worker

Is copying a large blob over to a worker expensive?

白昼怎懂夜的黑 提交于 2021-02-04 14:02:03
问题 Using the Fetch API I'm able to make a network request for a large asset of binary data (say more than 500 MB) and then convert the Response to either a Blob or an ArrayBuffer . Afterwards, I can either do worker.postMessage and let the standard structured clone algorithm copy the Blob over to a Web Worker or transfer the ArrayBuffer over to the worker context (making effectively no longer available from the main thread). At first, it would seem that it would be much preferable to fetch the

How to restart web workers when computer restarts from sleep mode?

帅比萌擦擦* 提交于 2021-01-29 14:32:26
问题 I have a simple webworker which keeps the current time of timezone using setInterval setInterval(() => { userTimezoneTimestamp = userTimezoneTimestamp + 1000 postMessage(userTimezoneTimestamp); }, 1000); It works fine until I put my machine on sleep mode. When I restart the machine from sleep mode, the time which I get from this worker is older. How can I restart my web worker only when the machine starts up from sleep mode? 回答1: There doesn't seem to be any DOM event letting us know about

Does web worker block on the main thread for some OffscreenCanvas functions?

旧巷老猫 提交于 2021-01-29 08:52:22
问题 I have a web worker processing an array of saved ImageData frames and am using an OffscreenCanvas 's context (created in the web worker) to putImageData . Meanwhile in my main thread I block on another operation. If I include the context.putImageData() call, the web worker blocks until my main thread completes before continuing, but if I remove the putImageData call or use context.clearRect() the web worker will run concurrently with my main thread. Even if I'm running in a web worker, is it

javascript:worker synchronization

邮差的信 提交于 2021-01-28 21:52:05
问题 I am working on HTML5 web worker and I made a function that spawn few workers and return the result, but problem is that it returns the value before the worker updates the result. So I want to delay return statement until all results are received for (i = 0; i < array1_rows; i++) { var worker = new Worker('json.js'); worker.postMessage(arr1[i]); worker.postMessage(arr2); worker.postMessage(i); worker.onmessage = storeResult; } ///////////////////////////////// return result; So I just want to

using angular modules in web workers

我是研究僧i 提交于 2021-01-28 12:14:15
问题 I am trying to use angular 8 jit compler in WEB WORKER but getting an error while trying to import the Compiler module or any other angular module in web-worker.ts file /// <reference lib="webworker" /> import {Compiler } from '@angular/core'; addEventListener('message', ({ data }) => { let response = `worker response to ` + data ; }); node_modules/@angular/core/core.d.ts:13052:20 - error TS2304: Cannot find name 'Document'. 回答1: Web worker doesn't have any access to the DOM, so the document

Javascript WebWorker - Async/Await

爱⌒轻易说出口 提交于 2021-01-20 20:47:22
问题 I am trying to offload long running process that blocks my UI. The WebWorker approach appears to be the best approach to this situation. However, one of the libraries that I need to use has async/await. The WebWorker has a limited JS API and does not appear to have async/await. Is there a way to use Promises inside of a WebWorker? Error ReferenceError: __awaiter is not defined Regards, Daniel Update: Adding an __awaiter lead to the Promise not being recognised. var __awaiter = (this && this._

Javascript WebWorker - Async/Await

会有一股神秘感。 提交于 2021-01-20 20:46:06
问题 I am trying to offload long running process that blocks my UI. The WebWorker approach appears to be the best approach to this situation. However, one of the libraries that I need to use has async/await. The WebWorker has a limited JS API and does not appear to have async/await. Is there a way to use Promises inside of a WebWorker? Error ReferenceError: __awaiter is not defined Regards, Daniel Update: Adding an __awaiter lead to the Promise not being recognised. var __awaiter = (this && this._

using WebAssembly in chrome extension

扶醉桌前 提交于 2021-01-20 14:32:58
问题 I have a chrome extension that includes a complicated function comp_func(data) which takes a lot of CPU by performing many bitwise operations. Because of that, I'm trying to use WebAssembly. I've tried to follow several tutorials, for example this one and this one. The first link says: fetch('simple.wasm').then(response => response.arrayBuffer() ).then(bytes => WebAssembly.instantiate(bytes, importObject) ).then(results => { results.instance.exports.exported_func(); }); but I get an error:

How does #onmessage and #postmessage work to communicate between main thread and HTML5's webworkers?

北城以北 提交于 2021-01-20 11:23:32
问题 I"m learning about HTML5 workers from here and the author uses self.onmessage and self.postmessage to communicate between the main thread and the worker "because the worker cannot access the DOM." But in the below it seems like self is referring to both the main thread and the worker. function CalculatePi(loop) { var c = parseInt(loop); var f = parseFloat(loop); var n=1; //these errors will need more work… if (isNaN(c) || f != c ) { throw("errInvalidNumber"); } else if (c<=0) { throw(

How to import a node module inside an angular web worker?

不羁岁月 提交于 2021-01-02 08:12:13
问题 I try to import a node module inside an Angular 8 web worker, but get an compile error 'Cannot find module'. Anyone know how to solve this? I created a new worker inside my electron project with ng generate web-worker app , like described in the above mentioned ng documentation. All works fine until i add some import like path or fs-extra e.g.: /// <reference lib="webworker" /> import * as path from 'path'; addEventListener('message', ({ data }) => { console.log(path.resolve('/')) const