Runs a function with a timeout.
The provided closure is invoked on a thread. If the thread completes
normally within the provided
duration, its result is returned. If the
thread panics within the provided
duration, the panic is propagated to the
timeout. Otherwise, a timeout error is returned.
Note that if the invoked function does not complete in the timeout, it is not killed; it is left to wind down normally. Therefore this function is only appropriate in tests, where the resource leak doesn’t matter.