Events: Difference between revisions
Content added Content deleted
(Added zkl) |
(→{{header|REXX}}: added the REXX language. -- ~~~~) |
||
Line 624: | Line 624: | ||
(void (sync task)) ; wait for the task to be done before exiting |
(void (sync task)) ; wait for the task to be done before exiting |
||
</lang> |
</lang> |
||
=={{header|REXX}}== |
|||
<lang rexx>/*REXX program shows a method of handling events (this is time-driven). */ |
|||
signal on halt /*allow the user to HALT the pgm.*/ |
|||
parse arg timeEvent /*allow "event" to be specified. */ |
|||
if timeEvent='' then timeEvent=5 /*if not specified, use default. */ |
|||
wait_for_event: do forever /*determine if an event occurred.*/ |
|||
theEvent=right(time(),1) /*maybe it's an event. */ |
|||
if pos(theEvent,timeEvent)\==0 then signal happening |
|||
end /*forever*/ |
|||
say 'Control should never get here!' /*This is a logic no-no occurance*/ |
|||
halt: say 'program halted.'; exit /*stick a fork in it, we're done.*/ |
|||
/*───────────────────────────────────HAPPENING processing───────────────*/ |
|||
happening: say 'an event occurred at' time()", the event is:" theEvent |
|||
do while theEvent==right(time(),1); /*process the event here.*/ nop;end |
|||
signal wait_for_event /*see if another event happened. */</lang> |
|||
'''output''' when using the input of: <tt> 1 3 5 0 7 9 </tt> |
|||
<pre> |
|||
an event occurred at 16:13:29, the event is: 9 |
|||
an event occurred at 16:13:30, the event is: 0 |
|||
an event occurred at 16:13:31, the event is: 1 |
|||
an event occurred at 16:13:33, the event is: 3 |
|||
an event occurred at 16:13:35, the event is: 5 |
|||
an event occurred at 16:13:37, the event is: 7 |
|||
an event occurred at 16:13:39, the event is: 9 |
|||
an event occurred at 16:13:40, the event is: 0 |
|||
an event occurred at 16:13:41, the event is: 1 |
|||
an event occurred at 16:13:43, the event is: 3 |
|||
an event occurred at 16:13:45, the event is: 5 |
|||
an event occurred at 16:13:47, the event is: 7 |
|||
an event occurred at 16:13:49, the event is: 9 |
|||
an event occurred at 16:13:50, the event is: 0 |
|||
an event occurred at 16:13:51, the event is: 1 |
|||
an event occurred at 16:13:53, the event is: 3 |
|||
program halted. |
|||
</pre> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |