1.0.3 • Published 2 years ago
web-thread v1.0.3
web-thread
介绍
支持vue、uni-app等框架的h5多线程封装库
软件架构
web worker相关功能封装,支持vue、uni-app等框架
安装教程
- 切换到h5项目根目录
- npm install --save web-thread
使用说明
const WebThread = require('web-thread');//引入依赖包
//子任务
let func = (arg1,arg2...) => {
self.postMessage("result")//回调数据
self.close()//关闭线程
return "res"//处理结果
}
//Array对应func的入参
let args = [arg1,arg2...]
/**
* @description 支持任务中实时回调
* @param {Function} work 要执行的任务
* @param {Array} args 要执行的任务的参数
* @param {Function} callback(执行结果,返回参数result) 回调函数
* @example 函数中使用
* self.postMessage(result)回调数据
* self.close()关闭线程
*/
WebThread.postCallback(func,args,(isSucc,res)=>{
//返回结果isSucc状态 res数据
})
/**
* @description 子线程完成调用后返回数据
* @param {function} work 要执行的任务
* @param {Array} args 要执行的任务的参数
* @return {Promise} 执行结果
*/
WebThread.post(func,args).then(res=>{
//执行完成
}).catch(e=>{
//执行错误
})