Skip to content

Commit

Permalink
Thinko + robustify by checking mirai::is_error_value() first and not …
Browse files Browse the repository at this point in the history
…relying on type [#7]
  • Loading branch information
HenrikBengtsson committed May 11, 2024
1 parent d243cd4 commit d599f27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: future.mirai
Version: 0.2.0-9003
Version: 0.2.0-9004
Depends:
future
Imports:
Expand Down
22 changes: 12 additions & 10 deletions R/nbrOfWorkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
nbrOfWorkers.mirai <- function(evaluator) {
res <- status()
workers <- res[["daemons"]]
if (is_error_value(workers)) {
reason <- capture.output(print(workers))
stop(FutureError(sprintf("mirai::status() failed to communicate with dispatcher: %s", reason)))
}

if (is.character(workers)) {
workers <- res[["connections"]]
stopifnot(is.numeric(workers))
} else if (is_error_value(res)) {
reason <- capture.output(print(res))
stop(FutureError(sprintf("mirai::status() failed to communicate with dispatcher: %s", reason)))
} else if (is.numeric(workers)) { ## NOTE: Must come after is_error_value()
} else {
} else if (!is.numeric(workers)) {
stop(FutureError(sprintf("Unknown type of mirai::daemons()$daemons: %s", typeof(workers))))
}

Expand All @@ -37,14 +38,15 @@ nbrOfWorkers.mirai <- function(evaluator) {
nbrOfFreeWorkers.mirai <- function(evaluator, background = FALSE, ...) {
res <- status()
workers <- res[["daemons"]]
if (is_error_value(workers)) {
reason <- capture.output(print(workers))
stop(FutureError(sprintf("mirai::status() failed to communicate with dispatcher: %s", reason)))
}

if (is.character(workers)) {
workers <- res[["connections"]]
stopifnot(is.numeric(workers))
} else if (is_error_value(res)) {
reason <- capture.output(print(res))
stop(FutureError(sprintf("mirai::status() failed to communicate with dispatcher: %s", reason)))
} else if (is.numeric(workers)) { ## NOTE: Must come after is_error_value()
} else {
} else if (!is.numeric(workers)) {
stop(FutureError(sprintf("Unknown type of mirai::daemons()$daemons: %s", typeof(workers))))
}

Expand Down
10 changes: 5 additions & 5 deletions R/utils,mirai.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
get_mirai_daemons <- function() {
status <- status()
res <- status[["daemons"]]

if (is_error_value(res)) { # should not assume structure of an error value
reason <- capture.output(print(res))
stop(FutureError(sprintf("mirai::status() failed to communicate with dispatcher: %s", reason)))
}

if (is.character(res)) {
# returns number of daemons if running without dispatcher
return(status[["connections"]])
}

if (is_error_value(res)) { # should not assume structure of an error value
reason <- capture.output(print(res))
stop(FutureError(sprintf("mirai::status() failed to communicate with dispatcher: %s", reason)))
}

as.data.frame(res)

}

0 comments on commit d599f27

Please sign in to comment.