Skip to content

thread 线程

用于实现多线程

js
const thread = require('thread')

call 执行

参数

参数类型说明
functionfunction执行函数

返回值

object

代码
javascript
const task = thread(() => a++)

get 获取返回值

参数

参数类型说明
timeoutnumber超时时间(可选)

返回值

object

代码
javascript
const task = thread(() => a++)
const result = task.get()

cancel 关闭

参数

参数类型说明
mayInterruptIfRunningboolean打断(可选)

返回值

boolean

代码
javascript
const task = thread(() => a++)
task.cancel()

isCancelled 是否已关闭

参数

返回值

boolean

代码
javascript
const task = thread(() => a++)
const isCancelled = task.isCancelled()

isDone 是否已完成

参数

返回值

boolean

代码
javascript
const task = thread(() => return a++ )
const isDone = task.isDone()