trap ctrl-c and exit nicely

J

Jim

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?
 
L

Logan Capaldo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top