The resource loading... loading...

join

The join() function is used to wait for the thread to exit and reclaim system resources.

The ThreadRet object contains data about the execution result. The properties include the following:

  • id: Thread Id.
  • terminated: Whether the thread is forced to end.
  • elapsed: The running time of the thread in nanoseconds.
  • ret: The return value of the thread function.


join()
join(timeout)

The ```timeout``` parameter is used to set the timeout in milliseconds for waiting for the thread to finish. When the ```timeout``` parameter is set to 0 or the ```timeout``` parameter is not set, the ```join()``` function will block and wait until the thread finishes executing. When the ```timeout``` parameter is set to -1, the ```join()``` function will return immediately.

timeout
false
number

```javascript
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}
}

Test the join() function for timeout and output the return value.

The join() function times out and returns 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