```peekMessage()```函数返回当前线程对象关联的线程收到的消息。
string、number、bool、object、array、空值等系统支持的所有类型
peekMessage()
peekMessage(timeout)
参数```timeout```为超时设置,会按照该参数设置的毫秒数阻塞等待,返回数据;没有数据并且超时则返回空值。如果```timeout```设置为0或者不传```timeout```参数,则表示一直阻塞等待,直到接收到通道中的数据。如果```timeout```设置为-1,则表示不阻塞并且立即返回数据,没有数据时返回空值。
timeout
false
number
```javascript
function main() {
var t1 = threading.Thread(function() {
for (var i = 0; i < 10; i++) {
Log("thread1 postMessage():", i)
threading.mainThread().postMessage(i)
Sleep(500)
}
})
while (true) {
var msg = threading.currentThread().peekMessage()
Log("main peekMessage():", msg)
if (msg == 9) {
break
}
Sleep(1000)
}
t1.join()
}
并发线程中向主线程发送消息。
在编写程序时需要注意线程死锁问题。
{@fun/Threads/Thread/postMessage postMessage}, {@fun/Threads/Thread/join join}, {@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}
threading postMessage