Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/req-perform-sequential.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ req_perform_sequential <- function(
interrupt = function(cnd) {
check_repeated_interrupt()

resps <- resps[seq_len(i)]
# interrupt might occur before request i completes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to truncate resps still?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this never had any effect, since it ran in the tryCatch handler and the local copy was never used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah resps <<- resps[seq_len(i)] was likely the intent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes more sense, that would follow req_perform_iterative() and truncate as well

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, that sounds like the goal.

if (is.null(resps[[i]])) {
i <- i - 1
}
resps <<- resps[seq_len(i)]
cli::cli_alert_warning(
"Terminating iteration; returning {i} response{?s}."
)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/req-perform-sequential.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
Error in `req_perform_sequential()`:
! If supplied, `paths` must be the same length as `reqs`.

# user termination returns completed responses

Code
resps <- req_perform_sequential(reqs)
Message
! Terminating iteration; returning 1 response.

17 changes: 17 additions & 0 deletions tests/testthat/test-req-perform-sequential.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,20 @@ test_that("mocking works", {
expect_equal(resps[[1]]$request, req_200)
expect_s3_class(resps[[2]], "httr2_http_404")
})

test_that("user termination returns completed responses", {
local_mocked_responses(function(req) {
if (req$url == "https://interrupt") {
interrupt()
}
response()
})
reqs <- list(
request("https://ok"),
request("https://interrupt"),
request("https://ok")
)

expect_snapshot(resps <- req_perform_sequential(reqs))
expect_length(resps, 1)
})
Loading