Skip to content

Commit

Permalink
FutureResults: Add internal resignalCondition() preparing for the mig…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
HenrikBengtsson committed Feb 22, 2018
1 parent 1f64268 commit a16343c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/Future-class.R
Expand Up @@ -271,7 +271,7 @@ value.Future <- function(future, signal = TRUE, ...) {
if (signal && future$state == "failed") {
mdebug("Future state: %s", sQuote(future$state))
mdebug("Future value: %s", sQuote(value))
stop(FutureEvaluationError(future))
resignalCondition(future) ## Will produce an error
}

value
Expand Down
32 changes: 26 additions & 6 deletions R/signalEarly.R
Expand Up @@ -28,20 +28,40 @@ signalEarly <- function(future, collect = TRUE, ...) {
if (!inherits(value, "condition")) return(future)

if (debug) mdebug("signalEarly(): signalCondition(v)")
resignalCondition(future)
if (debug) mdebug("signalEarly() ... DONE")

invisible(future)
}

resignalCondition <- function(future, ...) {
## Future is not yet launched
if (!future$state %in% c("finished", "failed")) {
stop(FutureError("Internal error: Future has not yet been resolved",
future = future))
}

value <- future$value

## Was a condition caught?
if (!inherits(value, "condition")) {
stop(FutureError("Internal error: Future did not produce a condition",
future = future))
}

cond <- value

## Signal detected condition
if (inherits(value, "error")) {
if (inherits(cond, "error")) {
stop(FutureEvaluationError(future))
} else if (inherits(value, "warning")) {
} else if (inherits(cond, "warning")) {
warning(FutureEvaluationWarning(future))
} else if (inherits(value, "message")) {
} else if (inherits(cond, "message")) {
message(FutureEvaluationMessage(future))
message("\n") ## TODO: Remove this? /HB 2018-02-03
} else {
signalCondition(value)
}

if (debug) mdebug("signalEarly() ... DONE")


invisible(future)
}

0 comments on commit a16343c

Please sign in to comment.