20,741
edits
| Line 34: | Line 34: | ||
Nasal has several ways to implement an iteration, including repeated events run from listeners or timers. | Nasal has several ways to implement an iteration, including repeated events run from listeners or timers. | ||
A polling loop, run via a timer, is akin to somebody permanently running to a room to check if the lights are on - a listener is like somebody being INSIDE the room SLEEPING and only WAKING up once the lights are turned on. | A polling loop, run via a timer, is akin to somebody permanently running to a room to check if the lights are on - a listener is like somebody being INSIDE the room SLEEPING and only WAKING up once the lights are turned on. | ||
The setlistener API is intended to catch rare events, whereas timers are run often, pretty much regardless of external events. Both are triggered by calling a so-called "callback" - which is just a provided function to be called, i.e. the | The setlistener API is intended to catch rare events, whereas timers are run often, pretty much regardless of external events. Both are triggered by calling a so-called "callback" - which is just a provided function to be called as the event-handler, i.e. the function specifies what is to be done once the event is triggered. | ||
In general, timers are not bad or expensive, because it really depends on what you're doing inside the callback (function) that is called, but some constructs benefit from listeners. | In general, timers are not bad or expensive, because it really depends on what you're doing inside the callback (function) that is called, but some constructs benefit from listeners. | ||