Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

AsyncQueue

AsyncQueue


Description

An AsyncQueue client

Super class

crul::AsyncVaried -> AsyncQueue

Public fields

bucket_size

(integer) number of requests to send at once

sleep

(integer) number of seconds to sleep between each bucket

req_per_min

(integer) requests per minute

Methods

Public methods


Method print()

print method for AsyncQueue objects

Usage
AsyncQueue$print(x, ...)
Arguments
x

self

...

ignored


Method new()

Create a new AsyncQueue object

Usage
AsyncQueue$new(
  ...,
  .list = list(),
  bucket_size = 5,
  sleep = NULL,
  req_per_min = NULL
)
Arguments
..., .list

Any number of objects of class HttpRequest(), must supply inputs to one of these parameters, but not both

bucket_size

(integer) number of requests to send at once. default: 5. See Details.

sleep

(integer) seconds to sleep between buckets. default: NULL (not set)

req_per_min

(integer) maximum number of requests per minute. if NULL (default), its ignored

Details

Must set either sleep or req_per_min. If you set req_per_min we calculate a new bucket_size when $new() is called

Returns

A new AsyncQueue object


Method request()

Execute asynchronous requests

Usage
AsyncQueue$request()
Returns

nothing, responses stored inside object, though will print messages if you choose verbose output


Method responses()

List responses

Usage
AsyncQueue$responses()
Returns

a list of HttpResponse objects, empty list before requests made


Method clone()

The objects of this class are cloneable with this method.

Usage
AsyncQueue$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other async: AsyncVaried, Async, HttpRequest

Examples

## Not run: 
# Using sleep
reqlist <- list(
  HttpRequest$new(url = "https://httpbin.org/get")$get(),
  HttpRequest$new(url = "https://httpbin.org/post")$post(),
  HttpRequest$new(url = "https://httpbin.org/put")$put(),
  HttpRequest$new(url = "https://httpbin.org/delete")$delete(),
  HttpRequest$new(url = "https://httpbin.org/get?g=5")$get(),
  HttpRequest$new(
    url = "https://httpbin.org/post")$post(body = list(y = 9)),
  HttpRequest$new(
    url = "https://httpbin.org/get")$get(query = list(hello = "world")),
  HttpRequest$new(url = "https://ropensci.org")$get(),
  HttpRequest$new(url = "https://ropensci.org/about")$get(),
  HttpRequest$new(url = "https://ropensci.org/packages")$get(),
  HttpRequest$new(url = "https://ropensci.org/community")$get(),
  HttpRequest$new(url = "https://ropensci.org/blog")$get(),
  HttpRequest$new(url = "https://ropensci.org/careers")$get()
)
out <- AsyncQueue$new(.list = reqlist, bucket_size = 5, sleep = 3)
out
out$bucket_size # bucket size
out$requests() # list requests
out$request() # make requests
out$responses() # list responses

# Using requests per minute
if (interactive()) {
x="https://raw.githubusercontent.com/ropensci/roregistry/gh-pages/registry_urls.json"
z <- HttpClient$new(x)$get()
urls <- jsonlite::fromJSON(z$parse("UTF-8"))$git_url
repos = Filter(length, regmatches(urls, gregexpr("ropensci/[A-Za-z]+", urls)))
repos = unlist(repos)
auth <- list(Authorization = paste("token", Sys.getenv('GITHUB_PAT')))
reqs <- lapply(repos[1:50], function(w) {
  HttpRequest$new(paste0("https://api.github.com/repos/", w), headers = auth)$get()
})

out <- AsyncQueue$new(.list = reqs, req_per_min = 30)
out
out$bucket_size
out$requests()
out$request()
out$responses()
}
## End(Not run)

crul

HTTP Client

v1.1.0
MIT + file LICENSE
Authors
Scott Chamberlain [aut, cre] (<https://orcid.org/0000-0003-1444-9135>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.