peekMessage()
函数用于从线程接收消息。
peekMessage()
函数返回当前线程对象关联的线程接收到的消息。
string / number / bool / object / array / any (系统支持的所有类型)
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}