Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web worker #1

Open
homobulla opened this issue Mar 19, 2018 · 1 comment
Open

Web worker #1

homobulla opened this issue Mar 19, 2018 · 1 comment

Comments

@homobulla
Copy link
Owner

No description provided.

@homobulla
Copy link
Owner Author

homobulla commented Mar 19, 2018

H5提出了Web worker,旨在解决js单线程的问题,以达到多线程的目的。
HTML5 中的 Web Worker 可以分为两种不同线程类型,一个是专用线程 Dedicated Worker,一个是共享线程 Shared Worker。

先看一个例子
主程序页面代码:
image
后台工作线程代码:
image

var worker = new Worker('numberworker.js'); 创建一个专用线程;
var worker = new SharedWorker('sharedworker.js', ’ mysharedworker ’ ); 共享线程创建
worker.postMessage("{first:347734080,second:3423744400}");通过postMessagenumberworker.js文件传递数据;
worker.onmessage函数来接受返回的数据;

也就是说,通信工具是postMessageonmessage,前者负责发送数据,后者负责接受数据。

link:
深入 HTML5 Web Worker 应用实践:多线程编程

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant