web-worker

HTML 5 webworkers with multiple arguments

女生的网名这么多〃 提交于 2019-12-19 19:52:54
问题 I just got into HTML5 webworkers and now I want to pass multiple arguments to my worker. I have this in my page: var username = document.getElementById("username").value; var server_url = 'localhost'; w.postMessage(username,server_url); and this in my worker: var username = ''; var server_url = ''; onmessage = function (e,f) { username = e.data; server_url = f.data; } console.log(username); console.log(server_url); and when I open it the page which calls the worker in the browser: Uncaught

Load Nodejs Module into A Web Worker

荒凉一梦 提交于 2019-12-19 02:54:14
问题 I'm intending to use web worker inside my Node.js application for some concurrent tasks. However since the 'webworker-threads' module follows the implementation of HTML5 web worker, requiring Nodejs modules like require("fs") inside web worker does not work. importScripts() can load js files but I would like a functionality inside the web worker so that I can require npm-installed modules. Is there a workaround for that? 回答1: author of webworker-threads here. Thank you for using the module!

Maximum running web worker html5 at the same

扶醉桌前 提交于 2019-12-18 16:48:30
问题 Is there any maximum count of web worker that can be run at the same time? Thanks a lot. 回答1: Yes and no. With Web Workers, there's no hard limit but you are limited by the available CPU and memory. There's a rather large amount of CPU and memory overhead that comes with each worker so you can bring the machine to a grind if you spin off a lot of workers. I'd say Web Workers are best used for "long running" background tasks of 100 milliseconds or more. 回答2: The w3c doesn't mention any

Structuring a TypeScript project with workers

ぃ、小莉子 提交于 2019-12-18 10:11:13
问题 How should I structure a project that includes main thread (DOM) script, and workers? Eg: main.ts // This file must have DOM types, but not worker types. const worker = new Worker('worker.js'); worker.onmessage = (event) => { // Ideally, I should be able to reference types from the worker: const data = event.data as import('./worker').HelloMessage; console.log(data.hello); }; worker.ts // This file must have worker types, but not DOM types. // The global object must be one of the worker

Any standard mechanism for detecting if a JavaScript is executing as a WebWorker?

↘锁芯ラ 提交于 2019-12-18 02:23:45
问题 A WebWorker executes with a scope completely separate from the 'window' context of traditional JavaScript. Is there a standard way for a script to determine if it is, itself, being executed as a WebWorker? The first 'hack' I can think of would be to detect if there is a 'window' property in the scope of the worker. If absent, this might mean we are executing as a WebWorker. Additional options would be to detect properties not present in a standard 'window' context. For Chrome 14, this list

Any standard mechanism for detecting if a JavaScript is executing as a WebWorker?

天大地大妈咪最大 提交于 2019-12-18 02:21:02
问题 A WebWorker executes with a scope completely separate from the 'window' context of traditional JavaScript. Is there a standard way for a script to determine if it is, itself, being executed as a WebWorker? The first 'hack' I can think of would be to detect if there is a 'window' property in the scope of the worker. If absent, this might mean we are executing as a WebWorker. Additional options would be to detect properties not present in a standard 'window' context. For Chrome 14, this list

how to send xmlhttprequest continuously in webworker?

偶尔善良 提交于 2019-12-17 17:22:45
问题 I am new to webworker but I managed to send xmlhttprequest to my rest api and I got json back. But I want send this request again and again (in a loop), until the page is active. I actually want to show values in real time. I want to make a simple web application in which when data is inserted in database my webworker should show that data without refreshing the page. Is there any better way to do so. Kindly help me in it. sorry for bad English. 回答1: You can use EventSource to get stream from

What are the use-cases for Web Workers? [closed]

人盡茶涼 提交于 2019-12-17 17:18:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I am looking for real-world scenarious for using Web Workers API. 回答1: John Resig (of jQuery fame) has a bunch of interesting examples of using web workers here - games, graphics, crypto. Another use is Web I/O - in other words, polling URLs in background. That way you don't block

HTML Web Worker and Jquery Ajax call

旧街凉风 提交于 2019-12-17 07:25:49
问题 I'm wondering if I can use jQuery inside the web worker file. Google Chrome gives me this error: "Uncaught ReferenceError: $ is not defined". Here is the code: The parent file: var loader = new Worker(BASE_URL + "js/rss_loader_worker.js"); // Ask the worker to start loading the RSS from the server loader.postMessage("loadRss"); // When receive the response from the server loader.onmessage = function (event) { console.log(event.data); } The worker file: onmessage = function (event) { if (event

Prevent browser freezing and crashing for long time calculation

我与影子孤独终老i 提交于 2019-12-14 02:14:32
问题 I need check in my database names who are duplicated and change this name to avoid duplicates. I using script suggested by @Jefré N. function eliminateDuplicates() { var repeats = {}; var error = false; //cache inputs var $inputs = $("input[type='text']"); //loop through inputs and update repeats for (i = 0; i < $inputs.length; ++i) { //cache current element var cur = $inputs[i]; //remove class $(cur).removeClass("double-error"); //get text of this element var text = $(cur).val(); //no text -