Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
game.json , you can specify the directory where Worker code is located. All JavaScript code in this directory will be bundled into a single JS file:{"workers": "workers"}
{"workers": {"path": "workers","isSubpackage": true // true means the Worker is packaged as a subpackage. Default is false. Setting false is equivalent to { "workers": "workers" }}}
workers/request/index.jsworkers/request/utils.jsworkers/response/index.js
├── game.js├── game.json├── project.config.json└── workers├── request│ ├── index.js│ └── utils.js└── response└── index.js
workers/request/index.js , write the Worker response code.const utils = require('./utils')// In the Worker thread execution context, a global worker object is exposed. Use worker.onMessage/postMessage directlyworker.onMessage(function (res) {console.log(res)})
const worker = wx.createWorker('workers/request/index.js') // Specify the Worker entry file path, absolute path
var task = wx.preDownloadSubpackage({packageType: "workers",success(res) {console.log("load worker success", res)var worker = wx.createWorker("workers/request/index.js") // Create Worker If the Worker subpackage is not fully downloaded, calling createWorker will result in an error},fail(res) {console.log("load worker fail", res)}})task.onProgressUpdate(res => {console.log(res.progress) // Monitor download progress using onProgressUpdateconsole.log(res.totalBytesWritten)console.log(res.totalBytesExpectedToWrite)})
worker.postMessage({msg: 'hello worker'})
wx series of APIs.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback