Taro.createWorker(scriptPath)
Creates a worker thread. You can create only one worker at most. Call Worker.terminate before creating another worker.
Type
(scriptPath: string) => Worker
Parameters
Property | Type | Description |
---|---|---|
scriptPath | string | The absolute path to the worker entry file. |
Sample Code
const worker = Taro.createWorker('workers/request/index.js')
worker.onMessage(function (res) {
console.log(res)
})
worker.postMessage({
msg: 'hello worker'
})
worker.terminate()
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.createWorker | ✔️ |