Forum: Ruby trap ctrl-c and exit nicely

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7c3a0706ce454a5e7c405a63fdcd2c21?d=identicon&s=25 Jim (Guest)
on 2005-12-17 17:33
(Received via mailing list)
Hello,

I want to trap a ctrl-c, wait for any http request to finish,and then
exit the program. I know I can Kernel#trap , but not sure how to wait
for the network operation to end. Do I need to perform the network
operation in a thread?
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2005-12-17 22:19
(Received via mailing list)
On Dec 17, 2005, at 11:32 AM, Jim wrote:

> Hello,
>
> I want to trap a ctrl-c, wait for any http request to finish,and then
> exit the program. I know I can Kernel#trap , but not sure how to wait
> for the network operation to end. Do I need to perform the network
> operation in a thread?
>
>

interrupted = false

trap("INT") { interrupted = true }

# do HTTP request

if interrupted
     exit
end

# rest of program
This topic is locked and can not be replied to.