0

How would I program a script to proceed to a function, if an if statement takes far too long to complete?

I am currently in a situation, where a chunk of code (depending on the network) can take anywhere from half a second, to half an hour to complete, and I am researching a code patch which would cause the code to skip the if statement and proceed to a new code function if it takes over 10 seconds to complete.

I suspect that the answer may lie within threads, however I am unsure as its a programming concept with which I have no experience. I am open to any answers, no matter how elaborate.

user4493605
  • 391
  • 2
  • 18

1 Answers1

0

An idiomatic solution is to use Timeout::timeout.

See https://stackoverflow.com/a/231662/393701 for an answer fitting your question.

Community
  • 1
  • 1
SirDarius
  • 41,440
  • 8
  • 86
  • 100