@@ -337,10 +337,55 @@ print.Future <- function(x, ...) {
337337 cat(sprintf(" Early signaling: %s\n " , isTRUE(future [[" earlySignal" ]])))
338338 cat(sprintf(" Environment: %s\n " , envname(future [[" envir" ]])))
339339
340+ result <- future [[" result" ]]
340341 state <- future [[" state" ]]
341- cat(sprintf(" State: %s\n " , commaq(state )))
342+ description <- switch (state ,
343+ created = {
344+ " Future was created, but is yet to be submitted"
345+ },
346+ submitted = {
347+ " Future has been submitted, but it is not known if it has been started"
348+ },
349+ running = {
350+ " Future is being evaluated"
351+ },
352+ finished = {
353+ stop_if_not(inherits(result , " FutureResult" ))
354+ conditions <- result [[" conditions" ]]
355+ n <- length(conditions )
356+ if (n == 0L ) {
357+ cond <- NULL
358+ } else {
359+ condition <- conditions [[n ]]
360+ cond <- condition [[" condition" ]]
361+ }
362+ if (inherits(cond , " error" )) {
363+ if (inherits(cond , " FutureInterruptError" )) {
364+ sprintf(" Future was interrupted during evaluation, resulting in a %s" , sQuote(class(cond )[1 ]))
365+ } else if (inherits(cond , " FutureError" )) {
366+ sprintf(" Future was resolved, but produced a %s" , sQuote(class(cond )[1 ]))
367+ } else {
368+ " Future was resolved, but produced a run-time error"
369+ }
370+ } else if (inherits(cond , " interrupt" )) {
371+ " Future was interrupted during evaluation"
372+ } else {
373+ " Future was resolved successfully"
374+ }
375+ },
376+ interrupted = {
377+ " Future was interrupted during evaluation"
378+ },
379+ canceled = {
380+ " Future was canceled"
381+ },
382+ failed = {
383+ " Future failed due to an unexpected, internal error during launch, evaluation, or while returning the results"
384+ },
385+ NA_character_
386+ )
387+ cat(sprintf(" State: %s (\" %s\" )\n " , commaq(state ), description ))
342388
343- result <- future [[" result" ]]
344389 hasResult <- inherits(result , " FutureResult" )
345390 # # BACKWARD COMPATIBILITY
346391 hasResult <- hasResult || exists(" value" , envir = future , inherits = FALSE )
@@ -477,16 +522,18 @@ run.Future <- function(future, ...) {
477522 if (debug ) mdebug_push(" Launching futures ..." )
478523 future [[" backend" ]] <- backend
479524 future [[" start" ]] <- proc.time()[[3 ]]
480- future2 <- tryCatch(
525+ future2 <- tryCatch({
481526 launchFuture(backend , future = future )
482- , FutureError = function (ex ) {
527+ }, FutureError = function (ex ) {
528+ future [[" state" ]] <- " failed"
483529 # # Known error caught by the future backend
484530 stop(ex )
485531 }, error = function (ex ) {
486532 # # Unexpected error
487533 msg <- conditionMessage(ex )
488534 label <- sQuoteLabel(future )
489535 msg <- sprintf(" Caught an unexpected error of class %s when trying to launch future (%s) on backend of class %s. The reason was: %s" , class(ex )[1 ], label , class(backend )[1 ], msg )
536+ future [[" state" ]] <- " failed"
490537 stop(FutureLaunchError(msg , future = future ))
491538 })
492539 if (debug ) mdebug_pop()
@@ -861,6 +908,48 @@ getExpression.Future <- local({
861908}) # # getExpression()
862909
863910
911+ # Future states:
912+ #
913+ # 1. `created`:
914+ # The future has been created, but not yet been submitted.
915+ # Examples:
916+ # A future created with `lazy = TRUE` is in this state.
917+ #
918+ # 2. `submitted`:
919+ # The future has been submitted for evaluation.
920+ # There is no evidence yet that the future is being evaluated.
921+ # Examples:
922+ # A future submitted to a queue may be in this state.
923+ #
924+ # 3. `running`:
925+ # The future is currently being evaluated.
926+ # There is no evidence yet that the evaluation of the future has finished.
927+ # Examples:
928+ # Future being processed by a worker is typically in this state.
929+ #
930+ # 4. `finished`:
931+ # The evaluation of the future has completed.
932+ # Examples:
933+ # A future submitted to a queue may be in this state.
934+ #
935+ # 5. `failed`:
936+ # The evaluation of the future has terminated, but failed before being
937+ # completed.
938+ # Examples:
939+ # A future that failed to launch.
940+ # An internal error occured while evaluating the future.
941+ # An internal error occured after finishing future evaluation, but
942+ # before return the results.
943+ #
944+ # 6. `interrupted`:
945+ # The evaluation of the future has terminated, but was interrupted before
946+ # being completed.
947+ # Examples:
948+ #
949+ # 7. `canceled`:
950+ # The evaluation of the future has terminated, but was canceled.
951+ # Examples:
952+ #
864953# ' @export
865954`$<-.Future` <- function (x , name , value ) {
866955 if (name == " state" ) {
0 commit comments