An async HTTP deferred object is also an event emitter, see
http_get()
for details, and also event_emitter.
URL to connect to.
HTTP headers to send.
If not NULL
, it must be a string, specifying a file.
The body of the response is written to this file.
Options to set on the handle. Passed to
curl::handle_setopt()
.
Progress handler function. It is only used if the response body is written to a file. See details below.
Deferred object.
Other asyncronous HTTP calls:
http_get()
,
http_setopt()
# \donttest{
afun <- async(function() {
dx <- http_head("https://eu.httpbin.org/status/200")$
then(function(x) x$status_code)
})
synchronise(afun())
#> [1] 200
# Check a list of URLs in parallel
afun <- function(urls) {
when_all(.list = lapply(urls, http_head))$
then(function(x) lapply(x, "[[", "status_code"))
}
urls <- c("https://google.com", "https://eu.httpbin.org")
synchronise(afun(urls))
#> [[1]]
#> [1] 200
#>
#> [[2]]
#> [1] 200
#>
# }