Originally Posted by sujithks81
Most languages support either code block references or function references. With either or those constructs, you can easily create a timeout wrapper.
In Ruby you can do blocks.
def wait_for(seconds: 10)
future = Time.new + timeout
while Time.new < future do
begin # Wrap the yield statement in a exception handling wrapper.
result = yield
if result != nil
break # When the result is no longer Nil, or an error break out of the loop.
# in your code later on you can use this method by passing in your block.
# Do some code that returns true when the wait condition matches.