Events: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.)
Line 772: Line 772:
=={{header|REXX}}==
=={{header|REXX}}==
Although REXX can be event driven, most events would probably have to be actively checked to see if the event occurs.
Although REXX can be event driven, most events would probably have to be actively checked to see if the event occurs.
<br>Here is a time-driven example of events happening, based on specific timer ticks.
<br>Here is a &nbsp; ''time-driven'' &nbsp; example of events happening, based on specific timer ticks.
<lang rexx>/*REXX program shows a method of handling events (this is time-driven). */
<lang rexx>/*REXX program demonstrates a method of handling events (this is a time─driven pgm).*/
signal on halt /*allow the user to HALT the pgm.*/
signal on halt /*allow the user to HALT the program.*/
parse arg timeEvent /*allow "event" to be specified. */
parse arg timeEvent /*allow the "event" to be specified. */
if timeEvent='' then timeEvent=5 /*if not specified, use default. */
if timeEvent='' then timeEvent=5 /*Not specified? Then use the default.*/


event?: do forever /*determine if an event occurred.*/
event?: do forever /*determine if an event has occurred. */
theEvent=right(time(),1) /*maybe it's an event, maybe not.*/
theEvent=right(time(),1) /*maybe it's an event, ─or─ maybe not.*/
if pos(theEvent,timeEvent)\==0 then signal happening
if pos(theEvent,timeEvent)\==0 then signal happening
end /*forever*/
end /*forever*/


say 'Control should never get here!' /*This is a logic no-no occurance*/
say 'Control should never get here!' /*This is a logic can─never─happen ! */
halt: say 'program halted.'; exit /*stick a fork in it, we're done.*/
halt: say '════════════ program halted.'; exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*───────────────────────────────────HAPPENING processing───────────────*/
happening: say 'an event occurred at' time()", the event is:" theEvent
happening: say 'an event occurred at' time()", the event is:" theEvent
do while theEvent==right(time(),1); /*process the event here.*/ nop;end
do while theEvent==right(time(),1)
signal event? /*see if another event happened. */</lang>
nop /*replace NOP with the "process" code.*/
end /*while*/ /*NOP is a special REXX statement. */
'''output''' when using the input of: &nbsp; <tt> 1 3 5 0 7 9 </tt>
signal event? /*see if another event has happened. */</lang>
'''output''' &nbsp; when using the input of: &nbsp; <tt> 1 &nbsp; 3 &nbsp; 5 &nbsp; 0 &nbsp; 7 &nbsp; 9 </tt>
<pre>
<pre>
an event occurred at 16:13:29, the event is: 9
an event occurred at 16:13:29, the event is: 9
Line 807: Line 809:
an event occurred at 16:13:51, the event is: 1
an event occurred at 16:13:51, the event is: 1
an event occurred at 16:13:53, the event is: 3
an event occurred at 16:13:53, the event is: 3
program halted.
════════════ program halted.
</pre>
</pre>