Handle a signal: Difference between revisions

Add Jsish
(Add Jsish)
Line 779:
4.5 seconds elapsed
</pre>
 
=={{header|Jsish}}==
<lang javascript>/* Handle a signal, is jsish */
 
var gotime = strptime();
var looping = true;
var loops = 1;
 
function handler() {
printf("Elapsed time: %ds\n", (strptime() - gotime) / 1000);
looping = false;
}
 
Signal.callback(handler, 'SIGINT');
Signal.handle('SIGINT');
 
while (looping) {
puts(loops++);
Event.update(500);
}</lang>
 
''Event.update(500)'' causes the event loop to be monitored for 500 milliseconds, sleeping when there are no events to process for the given interval. 0 would return immediately.
 
{{out}}
<pre>prompt$ jsish
Jsish interactive: see 'help [cmd]'
# source('handle-signal.jsi');
1
2
3
4
5
^CElapsed time: 2s
# </pre>
 
=={{header|Julia}}==
Anonymous user