当前位置:网站首页>Take an example of a web worker
Take an example of a web worker
2022-08-03 22:27:00 【Ziwei front end】
You need to follow the steps below to get started with web workersCount example
- Create a Web Worker file: You need to write a script to increment the count value.Let's name it counter.js
let i = 0; function timedCount() { i = i + 1; postMessage(i);setTimeout("timedCount()", 500); } timedCount();Here the postMessage() method is used to post the message backto HTML page
- Create Web Worker Object: You can create a Web Worker object by checking browser support.Let's name this file web_worker_example.js
if (typeof w == "undefined") { w = new Worker("counter.js"); }We can receive messages from web workers
w.onmessage = function (event) { document.getElementById("message").innerHTML = event.data; };- Terminate Web Worker: The Web Worker will continue to listen for messages (even after the external script completes) until it is terminated.You can use the terminate() method to terminate listening for messages.
w.terminate();- Reuse Web Workers: If the worker variable is set to undefined, code can be reused
w = undefined;边栏推荐
- With 4 years of work experience, the 5 communication methods between multi-threads can't be said, can you believe it?
- Bytebase数据库 Schema 变更管理工具
- 老板:公司系统太多,能不能实现账号互通?
- What is the difference between the generator version and the viewer version?
- utils timer
- HCIP第十五天
- Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
- Gains double award | know micro easily won the "2021 China digital twin solution suppliers in excellence" "made in China's smart excellent recommended products" double award!
- Shell编程的条件语句
- First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
猜你喜欢

Summary bug 】 【 Elipse garbled solution project code in Chinese!

嵌入式系统:概述

直播预告 | 构建业务智联,快速拥抱财务数字化转型
![[N1CTF 2018]eating_cms](/img/09/3599d889d9007eb45c6eab3043f0c4.png)
[N1CTF 2018]eating_cms

21天打卡挑战学习MySQL——《Window下安装MySql》第一周 第三篇

Gains double award | know micro easily won the "2021 China digital twin solution suppliers in excellence" "made in China's smart excellent recommended products" double award!

Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo

中国企业构建边缘计算解决方案的最佳实践

Adobe是什么?

Data_web(九)mongodb增量同步到mongodb
随机推荐
九种方式,教你读取 resources 目录下的文件路径
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
[N1CTF 2018]eating_cms
utils timer
Canvas App中点击图标生成PDF并保存到Dataverse中
Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
2022的七夕,奉上7个精美的表白代码,同时教大家快速改源码自用
授人以渔 - 如何自行查询任意 SAP UI5 控件属性的文档和技术实现细节试读版
[b01lers2020]Life on Mars
Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne
DO280管理和监控OpenShift平台--资源限制
for loop exercises
Quickly build a website with static files
480. Sliding Window Median
Bytebase数据库 Schema 变更管理工具
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
The development status of cloud computing at home and abroad
Nine ways to teach you to read the file path in the resources directory
剑指offer第22题-链表中倒数第K个节点
数据一致性:双删为什么要延时?