Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ruby

Idiom #230 Timeout

Cancel an ongoing processing p if it has not finished after 5s.

require 'timeout'
Timeout::timeout(5) { p }

On time out, this results in a TimeOut::Error object, which should be rescued.
The name p is also a built-in, though.
def main(p) do
  p
  |> Task.async()
  |> Task.await()
end

New implementation...
< >
programming-idioms.org