Skip to content

Instantly share code, notes, and snippets.

@DavisVaughan
Last active May 6, 2020 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavisVaughan/2a6316cdef7e5cebdba100db5e0fa92c to your computer and use it in GitHub Desktop.
Save DavisVaughan/2a6316cdef7e5cebdba100db5e0fa92c to your computer and use it in GitHub Desktop.
library(future)
library(progressr)
library(furrr)
# 2 cores
plan(multisession, workers = 2L)
x <- 1:20
random_sleep <- function() {
Sys.sleep(sample(1:3, size = 1L))
}
with_progress({
# Create a progressor
p <- progressor(along = x)
future_map(x, ~{
# Sleep for a random amount of time
random_sleep()
# Tick the progress bar
p()
})
})
# shut down the workers
plan(sequential)
@HenrikBengtsson
Copy link

Minor: To shut down workers, you need to switch to another plan - plan(sequential) is a good choice. Using plan() will only display the currently set future plan.

@DavisVaughan
Copy link
Author

DavisVaughan commented May 6, 2020

Woops! Thanks - updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment