Skip to main content
Version: Next

Taro.createWorker(scriptPath)

Creates a worker thread. You can create only one worker at most. Call Worker.terminate before creating another worker.

Reference

Type

(scriptPath: string) => Worker

Parameters

PropertyTypeDescription
scriptPathstringThe 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

APIWeChat Mini-ProgramH5React Native
Taro.createWorker✔️