Skip to content

Commit

Permalink
add async eg to mocking man file and mention async support on it
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jul 19, 2024
1 parent c5c5c24 commit 7827dfe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
21 changes: 19 additions & 2 deletions R/mocking.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#' Mocking HTTP requests
#'
#' Works for both synchronous requests via [HttpClient()] and async
#' requests via [Async()] and [AsyncVaried()]
#'
#' @export
#' @param on (logical) turn mocking on with `TRUE` or turn off with `FALSE`.
Expand All @@ -7,7 +10,6 @@
#' @examples \dontrun{
#'
#' if (interactive()) {
#' # load webmockr
#' library(webmockr)
#' library(crul)
#'
Expand All @@ -18,7 +20,6 @@
#'
#' # stub a request
#' stub_request("get", file.path(URL, "get"))
#' webmockr:::webmockr_stub_registry
#'
#' # create an HTTP client
#' (x <- HttpClient$new(url = URL))
Expand All @@ -31,6 +32,22 @@
#' x$get('get', query = list(foo = "bar"))
#' webmockr::webmockr_disable_net_connect()
#' x$get('get', query = list(foo = "bar"))
#'
#' # With Async
#' urls <- c(
#' file.path(URL, "get"),
#' file.path(URL, "anything"),
#' file.path(URL, "encoding/utf8")
#' )
#'
#' for (u in urls) {
#' webmockr::stub_request("get", u) %>%
#' webmockr::to_return(body = list(mocked = TRUE))
#' }
#'
#' async_con <- Async$new(urls = urls)
#' async_resp <- async_con$get()
#' lapply(async_resp, \(x) x$parse("UTF-8"))
#' }
#'
#' }
Expand Down
21 changes: 18 additions & 3 deletions man/mock.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7827dfe

Please sign in to comment.