## The function is currently defined as
function(..., seconds) {
fork_to_check <- parallel::mcparallel(
{eval(...)},
silent = FALSE)
# call mccollect to wait "seconds" for returning result of mcparallel.
my_result <- parallel::mccollect(fork_to_check, wait = FALSE, timeout = seconds)
# If my_result is returned kill fork
tools::pskill(fork_to_check$pid, tools::SIGKILL)
tools::pskill(-1 * fork_to_check$pid, tools::SIGKILL)
# kill the fork of forks if they were spawned
parallel::mccollect(fork_to_check, wait = FALSE)
# If the function mccollect had NULL (timedout), make stop
if (is.null(my_result))
stop("Time limit has reached!")
# remove list format
my_result <- my_result[[1]]
# return result
return(my_result)
}Run the code above in your browser using DataLab