当前位置:网站首页>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;
边栏推荐
- DO280管理和监控OpenShift平台--资源限制
- 斩获双奖|易知微荣获“2021中国数字孪生解决方案优秀供应商”“中国智能制造优秀推荐产品”双奖项!
- Cisco ike2 IPSec configuration
- How to write a database document management tool based on WPF (2)
- 伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
- 113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself
- Embedded Systems: GPIO
- Nine ways to teach you to read the file path in the resources directory
- 466. Count The Repetitions
- override学习(父类和子类)
猜你喜欢
随机推荐
L2-029 特立独行的幸福
易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
优化查询(工作中)
什么是memoization,它有什么用?
113. 授人以渔 - 如何自行查询任意 SAP UI5 控件属性的文档和技术实现细节
斩获双奖|易知微荣获“2021中国数字孪生解决方案优秀供应商”“中国智能制造优秀推荐产品”双奖项!
Nine ways to teach you to read the file path in the resources directory
PowerMockup 4.3.4::::Crack
【day6】类与对象、封装、构造方法
Adobe是什么?
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
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!
466. Count The Repetitions
pikachu Over permission 越权
for循环练习题
用于流动质押和收益生成的 Web3 基础设施
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
L2-041 插松枝
Golang第二章:程序结构
Embedded Systems: Clocks