maybe this? purrr::in_parallel
my_func <- function(x) {
Sys.sleep(1)
return(x * 2)
}
x <- 1:10
my_func(x)
#> [1] 2 4 6 8 10 12 14 16 18 20
mirai::daemons(5)
purrr::map(x, purrr::in_parallel(\(x) my_func(x), my_func = my_func))
#> [[1]]
#> [1] 2
#>
#> [[2]]
#> [1] 4
#>
#> [[3]]
#> [1] 6
#>
#> [[4]]
#> [1] 8
#>
#> [[5]]
#> [1] 10
#>
#> [[6]]
#> [1] 12
#>
#> [[7]]
#> [1] 14
#>
#> [[8]]
#> [1] 16
#>
#> [[9]]
#> [1] 18
#>
#> [[10]]
#> [1] 20
mirai::daemons(0)
Created on 2025-12-04 with reprex v2.1.1