Skip to content

Commit b9b5831

Browse files
nbrOfWorkers() now go via FutureBackend, if implemented
1 parent 83c7fd7 commit b9b5831

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

R/utils-prune_pkg_code.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ prune_call <- function(expr, name) {
1717
prune_fcns <- function(expr) {
1818
expr <- prune_call(expr, name = "stop_if_not")
1919
expr <- prune_call(expr, name = "with_assert")
20+
expr <- prune_call(expr, name = "assert_no_positional_args_but_first")
2021
expr
2122
}
2223

R/utils_api-nbrOfWorkers.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ nbrOfWorkers.cluster <- function(evaluator) {
4141
#' @export
4242
nbrOfWorkers.uniprocess <- function(evaluator) {
4343
assert_no_positional_args_but_first()
44-
45-
1L
44+
backend <- makeFutureBackend(evaluator)
45+
nbrOfWorkers(backend)
4646
}
4747

4848

@@ -65,6 +65,11 @@ nbrOfWorkers.multiprocess <- function(evaluator) {
6565
#' @export
6666
nbrOfWorkers.future <- function(evaluator) {
6767
assert_no_positional_args_but_first()
68+
69+
backend <- makeFutureBackend(evaluator)
70+
if (inherits(backend, "FutureBackend")) {
71+
return(nbrOfWorkers(backend))
72+
}
6873

6974
expr <- formals(evaluator)$workers
7075
workers <- eval(expr, enclos = baseenv())

tests/constant.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ y <- value(f)
1313
print(y)
1414
stopifnot(y == 42L)
1515

16-
17-
plan(constant)
18-
## No global variables
19-
f <- try(future(42L), silent = FALSE)
20-
print(f)
21-
stopifnot(inherits(f, "ConstantFuture"))
22-
23-
print(resolved(f))
24-
y <- value(f)
25-
print(y)
26-
stopifnot(y == 42L)
27-
2816
message("*** constant() ... DONE")
2917

3018
source("incl/end.R")

0 commit comments

Comments
 (0)