当前位置:网站首页>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;边栏推荐
- The sword refers to the offer question 22 - the Kth node from the bottom in the linked list
- Makefile
- 为什么我们需要回调
- HCIP第十三天
- 472. Concatenated Words
- CAS:153162-70-0_N-BOC-6-Biotinamidohexylamine
- Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
- Boss: There are too many systems in the company, can you realize account interoperability?
- UVa 437 - The Tower of Babylon(白书)
- 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!
猜你喜欢

获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》

LabVIEW code generation error 61056

七夕快乐!

直播预告 | 构建业务智联,快速拥抱财务数字化转型

2022-08-03 oracle执行慢SQL-Q17对比

目标检测技术研究现状及发展趋势

Quickly build a website with static files

藏宝计划TreasureProject(TPC)系统模式开发技术原理

【bug】汇总Elipse项目中代码中文乱码解决方法!

Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
随机推荐
HCIP第十五天
物联网新零售模式,引领购物新潮流
优化查询(工作中)
Work Subtotal QT Packing
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
E-commerce data warehouse ODS layer-----log data loading
HCIP第十四天
云计算国内外发展现状
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
2019年10月SQL注入的两倍
重发布实验报告
【MySQL进阶】数据库与表的创建和管理
Nine ways to teach you to read the file path in the resources directory
2022-08-02 mysql/stonedb慢SQL-Q18-内存使用暴涨分析
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
pikachu Over permission 越权
node连接mysql数据库报错:Client does not support authentication protocol requested by server
剑指offer第22题-链表中倒数第K个节点
Flink--Join以及Flink函数
UVa 10003 - Cutting Sticks (White Book, Interval DP)