Jump to content

Handle a signal: Difference between revisions

Added Wren
(Updated to compile with Nim 1.4.)
(Added Wren)
Line 1,851:
ENDPROC
</lang>
 
=={{header|Wren}}==
Note that Thread.sleep not only suspends the current fiber but also the System.clock method (possibly unintended). We therefore have to add back on the time slept.
<lang ecmascript>import "scheduler" for Scheduler
import "timer" for Timer
import "io" for Stdin
 
var start = System.clock
var main = Fiber.current
var stop = false
 
Scheduler.add {
var n = 0
while (true) {
System.print(n)
if (stop) {
var elapsed = System.clock - start + n * 0.5
System.print("Program has run for %(elapsed) seconds.")
main.transfer()
}
Timer.sleep(500)
n = n + 1
}
}
 
Stdin.isRaw = true // enable control characters to go into stdin
while (true) {
var b = Stdin.readByte()
if (b == 3 || b == 28) break // quits on pressing either Ctrl-C os Ctrl-\
}
Stdin.isRaw = false
stop = true</lang>
 
{{out}}
Sample run:
<pre>
0
1
2
3
4
5
6
7
8
9
10
11
12
Program has run for 6.00173 seconds.
</pre>
 
=={{header|X86 Assembly}}==
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.