Handle a signal

var start = Time.sec

Sig.INT {
    say "Ran for #{Time.sec - start} seconds."
    Sys.exit
}

{ |i|
    say i
    Sys.sleep(0.5)
} * Inf

Output:

1
2
3
4
^CRan for 2 seconds.

Last updated