Javascript Worker子线程代码实例

这篇文章主要介绍了JavaScript Worker子线程代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

mAIn.js code:

//创建
var worker = new Worker("./worker.js");

//发送
worker.postMessage(1);

//接收
worker.onmessage = (e)=>{
 console.log("main.js:");
 console.log(e.data);
}

worker.js code:

//接收
self.onmessage = (e)=>{

 console.log("worker.js:");
 console.log(e.data);
 
 //返回
 self.postMessage(e.data);
 
}
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容