线程相关 - js版引擎独享
javascript
const core = require('cheese-js');lua
local core = require('cheese-lua')创建线程:public create(callback: Callback): Thread ✅
用法示例:
javascript
const core = require('cheese-js'); //导入核心模块
const thread = new core.thread;
const base = core.base;
let th =thread.create(() =>{
while (true) {
console.log("我是子线程")
base.sleep(1000)
}
})
console.log("线程id",th.getId())
base.sleep(1000)
//一秒后停止
th.exit()lua
local core = require('cheese-lua')
local thread = core.thread.new()
local base = core.base
local th = thread:create(function()
while true do
print("我是子线程")
base.sleep(1000)
end
end)
print("线程id", th.getId())
base.sleep(1000)
th.exit()