Skip to content

Commit

Permalink
Improve progress bar handling
Browse files Browse the repository at this point in the history
When `req_perform_parallel()` is terminated, it seems like it's possible for a curl progress call to complete after the progress bar has been terminated.

Fixes #594
  • Loading branch information
hadley committed Dec 20, 2024
1 parent 962d50a commit 58b8a90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions R/multi-req.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ req_perform_parallel <- function(reqs,
perfs[[i]]$submit(pool)
}

progress$update(set = 0)
pool_run(pool, perfs, on_error = on_error)
progress$done()

Expand Down
11 changes: 9 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,19 @@ create_progress_bar <- function(total,

id <- exec(cli::cli_progress_bar, !!!args)

# These functions are called within multi_req_perform() from curl
# threads so the original progress may have gone away. If that has
# happened we'll just ignore the error.
list(
update = function(...) cli::cli_progress_update(..., id = id),
done = function() cli::cli_progress_done(id = id)
update = function(...) try_quiet(cli::cli_progress_update(..., id = id)),
done = function() try_quiet(cli::cli_progress_done(id = id))
)
}

try_quiet <- function(code) {
tryCatch(code, error = function(cnd) NULL)
}

imap <- function(.x, .f, ...) {
map2(.x, names(.x), .f, ...)
}
Expand Down

0 comments on commit 58b8a90

Please sign in to comment.