当前位置:网站首页>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;边栏推荐
猜你喜欢

静态文件快速建站

Conditional Statements for Shell Programming

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

Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"

LabVIEW code generation error 61056

Bytebase database schema change management tool

深度学习和机器学习有什么区别?

Shell编程的条件语句

override学习(父类和子类)

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
随机推荐
JPA Native Query(本地查询)及查询结果转换
utils timer
【MySQL进阶】数据库与表的创建和管理
LabVIEW代码生成错误 61056
utlis 线程池
113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself
九种方式,教你读取 resources 目录下的文件路径
图的基础概念
HCIP第十五天
[MySQL Advanced] Creation and Management of Databases and Tables
Golang第二章:程序结构
Why do we need callbacks
HCIP第十四天
物联网新零售模式,引领购物新潮流
什么是memoization,它有什么用?
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
384. Shuffle an Array
Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
如何基于WPF写一款数据库文档管理工具(二)
嵌入式系统:概述