Handles async events for all threads

Static variables

staticread onlycurrent:EventLoop

This is the current thread event loop. For platforms that doesn't support threads it is the same as main.

staticread onlymain:EventLoop

This is the main thread event loop.

Static methods

@:value({ blocking : true })staticaddTask(f:() ‑> Void, blocking:Bool = true):Void

Add a task to be run either on another thread or as part of the main event loop if the platform does not support threads.

statichasRunningThreads():Bool

Tells if we currently have blocking unfinished threads.

Constructor

new()

Variables

thread:Thread

Available on python, hl, neko, jvm, cpp, macro

The reference thread for this loop. If set, the loop can only be run within this thread.

Methods

@:value({ priority : 0 })add(callb:() ‑> Void, priority:Int = 0):Event

Add a callback to be run at each loop of the event loop.

@:value({ priority : 0 })addAsync(priority:Int = 0):Event

Similar to add but will return the Event before it's started. This is useful if you wish to hold a reference of another thread Event loop before it runs.

@:value({ priority : 0 })addTimer(callb:() ‑> Void, delay:Float, priority:Int = 0):Event

Add a callback to be run every delay seconds until stopped

deliver():Void

Deliver after a promise(). This will throw an exception if more deliver() calls has been made than corresponding promise() calls.

dispose():Void

This should be called after you are finished with a custom event loop. It is already automatically called for threads loops.

@:value({ blocking : true })hasEvents(blocking:Bool = true):Bool

Tells if the event loop has remaining events. If blocking is set to true, only check if it has remaining blocking events.

loop():Void

Runs until all the blocking events have been stopped. If this is called on the main thread, also wait for all blocking threads to finish.

@:value({ threadCheck : true })loopOnce(threadCheck:Bool = true):Void

Perform an update of pending events. By default, an event loop from a thread can only be triggered from this thread. You can set threadCheck to false in the rare cases you might want otherwise.

promise():Void

Promise a possible future event addition. This will prevent the loop() from terminating until the matching number of deliver() calls have been made.

@:value({ priority : 0 })run(callb:() ‑> Void, priority:Int = 0):Event

Add a function to be run once at next loop of the event loop.