Appearance
thread 线程
用于实现多线程
js
const thread = require('thread')call 执行
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| function | function | 执行函数 |
返回值
object
代码
javascript
const task = thread(() => a++)get 获取返回值
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| timeout | number | 超时时间(可选) |
返回值
object
代码
javascript
const task = thread(() => a++)
const result = task.get()cancel 关闭
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| mayInterruptIfRunning | boolean | 打断(可选) |
返回值
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()