Skip to content

Commit 58b8a90

Browse files
committed
Improve progress bar handling
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
1 parent 962d50a commit 58b8a90

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

R/multi-req.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ req_perform_parallel <- function(reqs,
7575
perfs[[i]]$submit(pool)
7676
}
7777

78+
progress$update(set = 0)
7879
pool_run(pool, perfs, on_error = on_error)
7980
progress$done()
8081

R/utils.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,19 @@ create_progress_bar <- function(total,
277277

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

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

289+
try_quiet <- function(code) {
290+
tryCatch(code, error = function(cnd) NULL)
291+
}
292+
286293
imap <- function(.x, .f, ...) {
287294
map2(.x, names(.x), .f, ...)
288295
}

0 commit comments

Comments
 (0)