Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.submit
Subscription
threading
Thread
Thread.peekMessage
Thread.postMessage
Thread.join
Thread.terminate
Thread.getData
Thread.setData
Thread.id
Thread.name
Thread.eventLoop
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Listens for events received by the current thread (the thread of the caller).

eventLoop()
eventLoop(timeout)

Examples

Concurrently execute 3 threads, outputting the received event information; when a timeout occurs or it returns immediately, the output is null.

javascript
function main() { var t1 = threading.Thread(function() { while (true) { var eventMsg = threading.currentThread().eventLoop() // Block and wait Log(_D(), "thread1 eventMsg:", eventMsg) // Output: 2024-11-14 10:14:18 thread1 eventMsg: {"Seq":1,"Event":"thread","ThreadId":0,"Index":1,"Queue":0,"Nano":1731550458699947000} } }) var t2 = threading.Thread(function() { while (true) { var eventMsg = threading.currentThread().eventLoop(-1) // Return immediately Log(_D(), "thread2 eventMsg:", eventMsg) Sleep(5000) } }) var t3 = threading.Thread(function() { while (true) { var eventMsg = threading.currentThread().eventLoop(3000) // Set a 3-second timeout Log(_D(), "thread3 eventMsg:", eventMsg) } }) t1.postMessage("Hello " + t1.name()) t2.postMessage("Hello " + t2.name()) t3.postMessage("Hello " + t3.name()) t1.join() t2.join() t3.join() }

Returns

TypeDescription

object / null value

Event information received by the current thread. For details, see Event Information Structure.

Arguments

NameTypeRequiredDescription

timeout

number

No

Timeout duration, in milliseconds. If timeout is set to 0, it blocks and waits indefinitely, returning only when an event occurs; if greater than 0, it sets the timeout duration for waiting for an event; if less than 0, it returns the most recent event immediately.

See Also

Remarks

The processing mechanism of the eventLoop() function is consistent with that of the global function EventLoop(). It always listens for events of the caller's thread, regardless of which Thread object it is called on; for example, calling t1.eventLoop() in the main thread returns main-thread events.