Skip to content
On this page

工作线程相关

typescript
import core from 'cheese-core';
const worker =  core.worker;

创建Worker线程: create(path: string,filename?:string): WorkerUtils

参数:

  • string (path): 绝对路径或上级路径 string (filename): 文件名

返回值:

  • 🟢ClassUtils: ClassUtils对象
  • 🔴null

用法示例:

typescript
//test.ts
import core from 'cheese-core';
const base = core.base;
console.log(env.jsObjects.get("1").name)
while (true) {
    base.sleep(1000)
    console.log("worker多线程")
}
typescript
//main.ts
class Person {
    name: string;
    age: number;

    constructor(name: string, age: number) {
        this.name = name;
        this.age = age;
    }
}
//创建worker进程并传递对象
let person1 = new Person("Alice", 30);
env.jsObjects.put("1",person1)
worker.create(os.JS_DIRECTORY.path+"/test.js")