library(parallel)
add <- function(a, b) {
Sys.sleep(1)
a + b
}
# R has no threads: the job runs in a forked
# process and mcparallel() returns at once
job <- mcparallel(add(3, 5))
cat("finish\n")
# NULL: the job has not finished yet
pending <- mccollect(job, wait = FALSE)
is_running <- is.null(pending)
# is_running = TRUE
cat("is_running =", is_running, "\n")