Events: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments, aligned statements, used a template for the output section.) |
|||
Line 1,109: | Line 1,109: | ||
<br>Here is a ''time-driven'' example of events happening, based on specific timer ticks. |
<br>Here is a ''time-driven'' example of events happening, based on specific timer ticks. |
||
<lang rexx>/*REXX program demonstrates a method of handling events (this is a time─driven pgm).*/ |
<lang rexx>/*REXX program demonstrates a method of handling events (this is a time─driven pgm).*/ |
||
signal on halt /*allow |
signal on halt /*allow user to HALT (Break) the pgm.*/ |
||
parse arg timeEvent /*allow the "event" to be specified. */ |
parse arg timeEvent /*allow the "event" to be specified. */ |
||
if timeEvent='' then timeEvent= |
if timeEvent='' then timeEvent= 5 /*Not specified? Then use the default.*/ |
||
event?: do forever /*determine if an event has occurred. */ |
event?: do forever /*determine if an event has occurred. */ |
||
theEvent=right(time(),1) |
theEvent= right(time(), 1) /*maybe it's an event, ─or─ maybe not.*/ |
||
if pos(theEvent,timeEvent) |
if pos(theEvent, timeEvent)>0 then signal happening |
||
end /*forever*/ |
end /*forever*/ |
||
say 'Control should never get here!' /*This is a logic can─never─happen ! */ |
say 'Control should never get here!' /*This is a logic can─never─happen ! */ |
||
halt: say '════════════ program halted.'; |
halt: say '════════════ program halted.'; exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
happening: say 'an event occurred at' time()", the event is:" theEvent |
happening: say 'an event occurred at' time()", the event is:" theEvent |
||
do |
do while theEvent==right(time(), 1) /*spin until a tic (a second) changes. */ |
||
nop /*replace NOP with the "process" code.*/ |
nop /*replace NOP with the "process" code.*/ |
||
end /*while*/ /*NOP |
end /*while*/ /*NOP is a REXX statement, does nothing*/ |
||
signal event? /*see if another event has happened. */</lang> |
|||
{{out|output|text= when using the input of: <tt> 1 3 5 0 7 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 |