当前位置:网站首页>举一个 web worker 的例子
举一个 web worker 的例子
2022-08-03 22:22:00 【紫微前端】
您需要按照以下步骤开始使用网络工作者进行计数示例
- 创建一个 Web Worker 文件:您需要编写一个脚本来增加计数值。我们将其命名为 counter.js
let i = 0; function timedCount() { i = i + 1; postMessage(i); setTimeout("timedCount()", 500); } timedCount();这里 postMessage() 方法用于将消息回传到 HTML 页面
- 创建 Web Worker 对象:您可以通过检查浏览器支持来创建 Web Worker 对象。让我们将此文件命名为 web_worker_example.js
if (typeof w == "undefined") { w = new Worker("counter.js"); }我们可以接收来自 web worker 的消息
w.onmessage = function (event) { document.getElementById("message").innerHTML = event.data; };- 终止 Web Worker:Web Worker 将继续侦听消息(即使在外部脚本完成后),直到它被终止。您可以使用 terminate() 方法来终止侦听消息。
w.terminate();- 重用 Web Worker:如果将 worker 变量设置为 undefined,则可以重用代码
w = undefined;边栏推荐
- 深度学习和机器学习有什么区别?
- 4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
- VLAN实验
- Golang Chapter 2: Program Structure
- 21天打卡挑战学习MySQL—Day第一周 第一篇
- Bytebase数据库 Schema 变更管理工具
- navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
- 2022-08-03 Oracle executes slow SQL-Q17 comparison
- Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne
- noip preliminary round
猜你喜欢

Canvas App中点击图标生成PDF并保存到Dataverse中

Adobe是什么?

【历史上的今天】8 月 3 日:微软研究院的创始人诞生;陌陌正式上线;苹果发布 Newton OS

投资性大于游戏性 NFT游戏到底是不是门好生意

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

如何设计 DAO 的 PoW 评判标准 并平衡不可能三角
![navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication](/img/09/a579c60e07cdc145175e72673409f7.png)
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication

CAS:908007-17-0_Biotin-azide _生物素叠氮化物

On the Qixi Festival of 2022, I will offer 7 exquisite confession codes, and at the same time teach you to quickly change the source code for your own use

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!
随机推荐
382. Linked List Random Node
Nine ways to teach you to read the file path in the resources directory
Kubernetes入门到精通-Operator 模式
【历史上的今天】8 月 3 日:微软研究院的创始人诞生;陌陌正式上线;苹果发布 Newton OS
Adobe是什么?
优化查询(工作中)
伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
『百日百题 · 基础篇』备战面试,坚持刷题 第四话——循环语句!
CAS:122567-66-2_DSPE-Biotin_DSPE-Biotin
472. Concatenated Words
mysql如何将表结构导出到excel
LitJson报错记录
483. Smallest Good Base
老板:公司系统太多,能不能实现账号互通?
2022-08-03 Oracle executes slow SQL-Q17 comparison
如何创建一个Web项目
CAS:122567-66-2_DSPE-生物素_DSPE-Biotin
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!
关于Yii2批量更新的操作
LabVIEW code generation error 61056