web-worker

Web worker Integration

半世苍凉 提交于 2020-02-06 07:36:05
问题 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

Can you share WebAssembly memory between Web Workers?

怎甘沉沦 提交于 2020-02-01 06:33:08
问题 Is it possible to share WebAssembly.memory between 2 workers by using postMessage, something like SharedArrayBuffer? And if the answer is yes, how? 回答1: You can create a WebAssembly shared memory instance via the JavaScript API: const memory = new WebAssembly.Memory({ initial: 80, maximum: 80, shared: true }); You can then send this memory instance to a Web Worker via postMessage : const worker = new Worker("worker.js"); worker.postMessage({ memory }); The file worker.js can then create a

How do I strongly type a TypeScript web worker file with postMessage?

試著忘記壹切 提交于 2020-02-01 05:34:16
问题 I have a web worker that I want to write with TypeScript. The problem is Worker.postMessage - TypeScript assumes that every script will be loaded in the window context, and so expects Window.postMessage, which has a different syntax. This means TypeScript throws an error when I try to use postMessage . There are ways to work around this, for instance by redefining the function declare function postMessage(message: any) , but most of these are ugly kludges at best - the whole point of TS is

How to make web workers with TypeScript and webpack

不羁的心 提交于 2020-01-28 03:47:05
问题 I'm having some issues with properly compiling my typescript when I attempt to use web workers. I have a worker defined like this: onmessage = (event:MessageEvent) => { var files:FileList = event.data; for (var i = 0; i < files.length; i++) { postMessage(files[i]); } }; In another part of my application i'm using the webpack worker loader to load my worker like this: let Worker = require('worker!../../../workers/uploader/main'); I'm however having some issues with making the typescript

How to make web workers with TypeScript and webpack

扶醉桌前 提交于 2020-01-28 03:47:04
问题 I'm having some issues with properly compiling my typescript when I attempt to use web workers. I have a worker defined like this: onmessage = (event:MessageEvent) => { var files:FileList = event.data; for (var i = 0; i < files.length; i++) { postMessage(files[i]); } }; In another part of my application i'm using the webpack worker loader to load my worker like this: let Worker = require('worker!../../../workers/uploader/main'); I'm however having some issues with making the typescript

PHP - How to check if request is for JS worker

雨燕双飞 提交于 2020-01-24 23:04:37
问题 After consulting MDN for the referrer-policy and Googling, DuckDucking and StackOverlow-searching, maybe you can help me with this rather simple (yet illusive) issue? Process Flow the browser makes a request to the server based on the HTTP_REFERER header, the server decides a response but why? (you ask) This is part of an elaborate set of security checks, in this case deciding if the client has access to a file requested FUBU (for us by us). This will not work if the referer is missing, but

Can I pass parameters to .js function when I create the new Web Workers object?

痴心易碎 提交于 2020-01-23 06:29:46
问题 When I create a web workers like the following... var w = new Worker("./Scripts/sample.js"); sample.js want to some parameters from the caller!! Possible? 回答1: I haven't used web workers a whole bunch, but per this description I believe you could do it along these lines: var worker = new Worker("sample.js"); worker.postMessage({ "args": [ ] }); Then, in sample.js, structure it along these lines: self.addEventListener("message", function(e) { var args = e.data.args; // do whatever you need

<Permission denied> error trying to instantiate web worker object

谁都会走 提交于 2020-01-17 04:25:08
问题 Trying out the web worker API for the first time and can't seem to get a response from the background worker. Markup: <script src="~/Scripts/script.js"></script> <button onclick="TriggerWorker()">Trigger Worker</button> Contents of script.js file: function TriggerWorker() { var myWorker = new Worker('worker.js'); myWorker.onmessage = function (e) { console.log(e.data); } console.log(myWorker); myWorker.postMessage("Text sent to worker"); } Contents of worker.js file: onmessage = function (e)

Force reload/prevent cache of Web Workers

試著忘記壹切 提交于 2020-01-14 09:38:21
问题 I've noticed that most browsers (Chrome in particular) seem to cache web worker scripts even after you force the page to reload (SHIFT+F5, etc). The only reliable way I've found to force the cache to update is to type the worker script's path into the address bar and force reload it separately. Obviously this is a royal pain when trying to develop, well, anything. Does anyone know of a reliable way to either stop the browser from caching worker scripts OR force it to reload them in a simple

How to use a Web Worker in AngularJS?

纵饮孤独 提交于 2020-01-14 08:16:29
问题 I'm using AngularJS Seed and I want to see a working implementation of a Web Worker. I want to make a simple Web Worker work in order to understand it, but I'm running into an issue with the functionality. I have the Web Worker code in the services.js like so: 'use strict'; /* Services */ var app = angular.module('myApp.services', []). app.factory("HelloWorldService",['$q',function($q){ var worker = new Worker('js/doWork.js'); var defer; worker.addEventListener('message', function(e) {