join()
函数用于等待线程退出,并回收系统资源。
ThreadRet
对象包含执行结果的相关数据,包含的属性如下:
ThreadRet
对象
join() join(timeout)
timeout
参数用于设置等待线程结束的超时时间,单位为毫秒。timeout
参数设置为0或者不设置timeout
参数时join()
函数会阻塞,等待到线程执行结束。timeout
参数设置为-1时,join()
函数会立即返回。
timeout false number
function main() {
var t1 = threading.Thread(function() {
Log("Hello thread1")
Sleep(5000)
})
var ret = t1.join(1000)
Log("ret:", ret) // ret: undefined
ret = t1.join()
Log("ret:", ret) // ret: {"id":1,"terminated":false,"elapsed":5003252000}
}
测试join()
函数超时,输出返回值。
join()
函数超时,返回undefined
。
{@fun/Threads/Thread/peekMessage peekMessage}, {@fun/Threads/Thread/postMessage postMessage}, {@fun/Threads/Thread/terminate terminate}, {@fun/Threads/Thread/getData getData}, {@fun/Threads/Thread/setData setData}, {@fun/Threads/Thread/id id}, {@fun/Threads/Thread/name name}, {@fun/Threads/Thread/eventLoop eventLoop}
postMessage terminate