当前位置:网站首页>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;边栏推荐
- 九种方式,教你读取 resources 目录下的文件路径
- UVa 437 - The Tower of Babylon(白书)
- for loop exercises
- 目标检测技术研究现状及发展趋势
- win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
- What is the difference between the generator version and the viewer version?
- How to write a database document management tool based on WPF (2)
- 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!
- FinClip最易用的智能电视小程序
- 电商秒杀系统
猜你喜欢

【开源框架】国内首个通用云计算框架,任意程序都可做成云计算。

生成器版和查看器版有什么区别?

Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne

pikachu Over permission

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!

《数字经济全景白皮书》金融数字用户篇 重磅发布!

【day6】类与对象、封装、构造方法

113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself

全球观之地理部分

2022-08-03 oracle执行慢SQL-Q17对比
随机推荐
如何基于WPF写一款数据库文档管理工具(二)
Summary bug 】 【 Elipse garbled solution project code in Chinese!
Golang第一章:入门
CAS:1620523-64-9_Azide-SS-biotin_biotin-disulfide-azide
noip初赛
一个函数有多少种调用方式?
JPA Native Query(本地查询)及查询结果转换
重发布实验报告
UVa 10003 - Cutting Sticks (White Book, Interval DP)
Basic Concepts of Graphs
Cisco ike2 IPSec配置
2022-08-02 mysql/stonedb慢SQL-Q18-内存使用暴涨分析
老板:公司系统太多,能不能实现账号互通?
golang写的存储引擎,基于b+树,mmap
2019年10月SQL注入的两倍
易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
Shell编程的条件语句
嵌入式系统:时钟
关于IDO预售系统开发技术讲解丨浅谈IDO预售合约系统开发原理分析
优化查询(工作中)