24
/41
Event based programming: Listener
User events must be Listened.
Warning
Cannot use standard 'while loops', otherwise the system is blocked waiting one event.
// Doesn't work: The program is blocked in the loop !
while
(
event
===
false
)
{
...
check
(
event
);
}
Use of built-in
Listeners
- Non blocking functions waiting for an event to happen
- Can be implemented as stack of events, asynchronous threads, etc.
In JS:
[x].addEventListener(eventName, [x]);