Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support async requests from crul #246

Closed
d-sci opened this issue Jul 14, 2022 · 3 comments · Fixed by ropensci/crul#180
Closed

Support async requests from crul #246

d-sci opened this issue Jul 14, 2022 · 3 comments · Fixed by ropensci/crul#180
Milestone

Comments

@d-sci
Copy link

d-sci commented Jul 14, 2022

I wanted to test my crul code that uses Async, but it doesn't seem to be supported. Minimal reprex below:

library(vcr)

# This works
use_cassette("sync", {
  crul::HttpClient$new(url = "https://httpbin.org/get")$get()
})
#> <vcr - Cassette> sync
#>   Record method: once
#>   Serialize with: yaml
#>   Persist with: FileSystem
#>   Re-record interval (s): 
#>   Clean outdated interactions?: FALSE
#>   update_content_length_header: FALSE
#>   allow_playback_repeats: FALSE
#>   allow_unused_http_interactions: 
#>   exclusive: 
#>   preserve_exact_body_bytes: FALSE
file.exists("sync.yml")
#> [1] TRUE

# This doesn't
use_cassette("async", {
  req1 <- crul::HttpRequest$new(url = "https://httpbin.org/get")$get()
  req2 <- crul::HttpRequest$new(url = "https://httpbin.org/get")$get()
  out <- crul::AsyncVaried$new(req1, req2)
  out$request()
})
#> Warning: Empty cassette (async) deleted; consider the following:
#>  - If an error occurred resolve that first, then check:
#>  - vcr only supports crul & httr; requests w/ curl, download.file, etc. are not supported
#>  - If you are using crul/httr, are you sure you made an HTTP request?
#> <vcr - Cassette> async
#>   Record method: once
#>   Serialize with: yaml
#>   Persist with: FileSystem
#>   Re-record interval (s): 
#>   Clean outdated interactions?: FALSE
#>   update_content_length_header: FALSE
#>   allow_playback_repeats: FALSE
#>   allow_unused_http_interactions: 
#>   exclusive: 
#>   preserve_exact_body_bytes: FALSE
file.exists("async.yml")
#> [1] FALSE
Session Info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.1.0 (2021-05-18)
#>  os       macOS Big Sur 10.16
#>  system   x86_64, darwin17.0
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Toronto
#>  date     2022-07-14
#>  pandoc   2.14.0.3 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  base64enc     0.1-3   2015-07-28 [1] CRAN (R 4.1.0)
#>  brio          1.1.3   2021-11-30 [1] CRAN (R 4.1.0)
#>  cachem        1.0.6   2021-08-19 [1] CRAN (R 4.1.0)
#>  callr         3.7.0   2021-04-20 [1] CRAN (R 4.1.0)
#>  cli           3.3.0   2022-04-25 [1] CRAN (R 4.1.0)
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.1.0)
#>  crul          1.2.0   2021-11-22 [1] CRAN (R 4.1.0)
#>  curl          4.3.2   2021-06-23 [1] CRAN (R 4.1.0)
#>  desc          1.4.1   2022-03-06 [1] CRAN (R 4.1.2)
#>  devtools      2.4.3   2021-11-30 [1] CRAN (R 4.1.0)
#>  digest        0.6.28  2021-09-23 [1] CRAN (R 4.1.0)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.0)
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
#>  fauxpas       0.5.0   2020-04-13 [1] CRAN (R 4.1.0)
#>  fs            1.5.2   2021-12-08 [1] CRAN (R 4.1.0)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.1.2)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.0)
#>  httpcode      0.3.0   2020-04-10 [1] CRAN (R 4.1.0)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.1.0)
#>  jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.1.0)
#>  knitr         1.37    2021-12-16 [1] CRAN (R 4.1.0)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.0)
#>  memoise       2.0.1   2021-11-26 [1] CRAN (R 4.1.0)
#>  pillar        1.6.3   2021-09-26 [1] CRAN (R 4.1.0)
#>  pkgbuild      1.3.1   2021-12-20 [1] CRAN (R 4.1.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
#>  pkgload       1.2.4   2021-11-30 [1] CRAN (R 4.1.0)
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.1.0)
#>  processx      3.5.2   2021-04-30 [1] CRAN (R 4.1.0)
#>  ps            1.6.0   2021-02-28 [1] CRAN (R 4.1.0)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
#>  R.cache       0.15.0  2021-04-30 [1] CRAN (R 4.1.0)
#>  R.methodsS3   1.8.1   2020-08-26 [1] CRAN (R 4.1.0)
#>  R.oo          1.24.0  2020-08-26 [1] CRAN (R 4.1.0)
#>  R.utils       2.11.0  2021-09-26 [1] CRAN (R 4.1.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.0)
#>  Rcpp          1.0.7   2021-07-07 [1] CRAN (R 4.1.0)
#>  remotes       2.4.2   2021-11-30 [1] CRAN (R 4.1.0)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.0)
#>  rlang         1.0.2   2022-03-04 [1] CRAN (R 4.1.2)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.0)
#>  rprojroot     2.0.3   2022-04-02 [1] CRAN (R 4.1.2)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.1.0)
#>  stringi       1.7.6   2021-11-29 [1] CRAN (R 4.1.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
#>  styler        1.7.0   2022-03-13 [1] CRAN (R 4.1.2)
#>  testthat      3.1.4   2022-04-26 [1] CRAN (R 4.1.2)
#>  tibble        3.1.5   2021-09-30 [1] CRAN (R 4.1.0)
#>  triebeard     0.3.0   2016-08-04 [1] CRAN (R 4.1.0)
#>  urltools      1.7.3   2019-04-14 [1] CRAN (R 4.1.0)
#>  usethis       2.1.6   2022-05-25 [1] CRAN (R 4.1.2)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
#>  vcr         * 1.0.2   2021-05-31 [1] CRAN (R 4.1.0)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
#>  webmockr      0.8.0   2021-03-14 [1] CRAN (R 4.1.0)
#>  whisker       0.4     2019-08-28 [1] CRAN (R 4.1.0)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.1.2)
#>  xfun          0.29    2021-12-14 [1] CRAN (R 4.1.0)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.1.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@sckott
Copy link
Collaborator

sckott commented Jul 15, 2022

hi @d-sci thanks for the issue. Unfortunately, vcr does not support async (related ropensci/crul#78)

All my R pkgs are now hobby projects, so your best bet for this happening is to submit a pull request. If you're interested, here's where the hook is in crul for non async https://github.com/ropensci/crul/blob/main/R/client.R#L511-L517 - I think I played with async support but I can't remember what the pain points were. The request construction is very different for async https://github.com/ropensci/crul/blob/main/R/asyncvaried.R as you can see

@sckott
Copy link
Collaborator

sckott commented Nov 8, 2022

closing, but we can reopen if someone wants to tackle this

@sckott
Copy link
Collaborator

sckott commented Jul 18, 2024

re-opened b/c of ropensci/crul#180

@sckott sckott closed this as completed in 6c78b83 Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants