Aliases: multi multi_add multi_run multi_set multi_list multi_cancel new_pool multi_fdset
Keywords:
### ** Examples results <- list() success <- function(x){ results <<- append(results, list(x)) } failure <- function(str){ cat(paste("Failed request:", str), file = stderr()) } # This handle will take longest (3sec) h1 <- new_handle(url = "https://hb.cran.dev/delay/3") multi_add(h1, done = success, fail = failure)
<curl handle> (https://hb.cran.dev/delay/3)
# This handle writes data to a file con <- file("output.txt") h2 <- new_handle(url = "https://hb.cran.dev/post", postfields = "bla bla") multi_add(h2, done = success, fail = failure, data = con)
<curl handle> (https://hb.cran.dev/post)
# This handle raises an error h3 <- new_handle(url = "https://urldoesnotexist.xyz") multi_add(h3, done = success, fail = failure)
<curl handle> (https://urldoesnotexist.xyz)
# Actually perform the requests multi_run(timeout = 2)
$success [1] 1 $error [1] 1 $pending [1] 1
multi_run()
$success [1] 1 $error [1] 0 $pending [1] 0
# Check the file readLines("output.txt")
[1] "{" [2] " \"args\": {}, " [3] " \"data\": \"\", " [4] " \"files\": {}, " [5] " \"form\": {" [6] " \"bla bla\": \"\"" [7] " }, " [8] " \"headers\": {" [9] " \"Accept\": \"*/*\", " [10] " \"Accept-Encoding\": \"gzip, br\", " [11] " \"Cdn-Loop\": \"cloudflare; loops=1\", " [12] " \"Cf-Connecting-Ip\": \"130.216.254.224\", " [13] " \"Cf-Ipcountry\": \"NZ\", " [14] " \"Cf-Ray\": \"96d8e8824a3c7256-EWR\", " [15] " \"Cf-Visitor\": \"{\\\"scheme\\\":\\\"https\\\"}\", " [16] " \"Connection\": \"close\", " [17] " \"Content-Length\": \"7\", " [18] " \"Content-Type\": \"application/x-www-form-urlencoded\", " [19] " \"Host\": \"httpbin:8080\", " [20] " \"User-Agent\": \"R (4.2.3 x86_64-pc-linux-gnu x86_64 linux-gnu) - RCloud (http://github.com/att/rcloud)\"" [21] " }, " [22] " \"json\": null, " [23] " \"origin\": \"130.216.254.224\", " [24] " \"url\": \"https://httpbin:8080/post\"" [25] "}"
unlink("output.txt")