Skip to content

Commit 3c45442

Browse files
Avoid re-adding 'result' back to interrupted future
1 parent 2c9351b commit 3c45442

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

R/backend_api-FutureBackend-class.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,17 @@ resetFuture.FutureBackend <- function(backend, future, ...) {
7676
"calls",
7777
"state"
7878
)
79-
class(future) <- "Future"
8079

80+
class(future) <- "Future"
81+
8182
drop <- setdiff(names(future), core_fields)
8283
for (name in drop) {
8384
future[[name]] <- NULL
8485
}
8586

8687
future[["state"]] <- "created"
8788
future[["lazy"]] <- TRUE
88-
89+
8990
future
9091
}
9192

R/protected_api-signalConditions.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
signalConditions <- function(future, include = "condition", exclude = NULL, resignal = TRUE, ...) {
2828
## Nothing to do?
2929
if (length(include) == 0L) return(invisible(future))
30-
30+
3131
## Future is not yet launched
32-
if (!future[["state"]] %in% c("finished", "failed")) {
32+
if (!future[["state"]] %in% c("finished", "failed", "interrupted")) {
3333
stop(FutureError(
3434
sprintf(
3535
"Internal error: Cannot resignal future conditions. %s has not yet been resolved (state = %s)",
@@ -73,7 +73,7 @@ signalConditions <- function(future, include = "condition", exclude = NULL, resi
7373
## Don't signal condition based on 'include'?
7474
if (length(include) > 0L && !inherits(condition, include)) next
7575

76-
mdebugf(" - Condition #%d: %s", kk, paste(sQuote(class(condition)), collapse = ", "))
76+
if (debug) mdebugf(" - Condition #%d: %s", kk, paste(sQuote(class(condition)), collapse = ", "))
7777

7878
## Flag condition as signaled
7979
cond[["signaled"]] <- cond[["signaled"]] + 1L
@@ -104,8 +104,12 @@ signalConditions <- function(future, include = "condition", exclude = NULL, resi
104104
pid <- source[["pid"]]
105105
msg <- sprintf("A future ('%s') of class %s was interrupted at %s, while running on %s (pid %s). The future was reset to a vanilla, lazy future, which can be re-evaluted again", label, class(future)[1], format(when, format = "%FT%T"), sQuote(host), pid)
106106
backend <- future[["backend"]]
107-
if (!is.null(backend)) future <- resetFuture(backend, future)
107+
if (!is.null(backend)) {
108+
if (debug) mdebugf(" - Resetting future")
109+
future <- resetFuture(backend, future)
110+
}
108111
warning(FutureInterruptWarning(msg, future = future))
112+
return(invisible(future))
109113
} else if (inherits(condition, "warning")) {
110114
warning(condition)
111115
} else if (inherits(condition, "message")) {
@@ -122,7 +126,7 @@ signalConditions <- function(future, include = "condition", exclude = NULL, resi
122126
if (isTRUE(attr(future[["conditions"]], "drop"))) {
123127
conditions <- conditions[!signaled]
124128
}
125-
129+
126130
## Make sure to update 'signaled' information on exit
127131
result[["conditions"]] <- conditions
128132
future[["result"]] <- result

0 commit comments

Comments
 (0)