Skip to content

Commit 4ff28fc

Browse files
Memoize cluster timeout options related to cluster futures; this should really be done when plan() is configured
1 parent b3208c4 commit 4ff28fc

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

R/backend_api-ClusterFuture-class.R

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ ClusterFutureBackend0 <- local({
713713
NA_integer_
714714
}
715715

716+
.timeout <- NULL
717+
716718
function(workers, persistent = FALSE) {
717719
## Attach name to cluster?
718720
name <- attr(workers, "name", exact = TRUE)
@@ -792,7 +794,7 @@ ClusterFutureBackend0 <- local({
792794
mdebug("isFutureResolved() ...")
793795
on.exit(mdebug("isFutureResolved() ... done"))
794796
}
795-
797+
796798
node_idx <- future[["node"]]
797799
cl <- workers[node_idx]
798800
node <- cl[[1]]
@@ -804,13 +806,27 @@ ClusterFutureBackend0 <- local({
804806
if (!is.na(connId) && connId < 0L) return(FALSE)
805807

806808
assertValidConnection(future)
807-
809+
808810
if (is.null(timeout)) {
809-
timeout <- getOption("future.cluster.resolved.timeout")
810-
if (is.null(timeout)) timeout <- getOption("future.resolved.timeout", 0.01)
811-
if (timeout < 0) {
812-
warning("Secret option 'future.resolved.timeout' is negative, which causes resolved() to wait until the future is resolved. This feature is only used for testing purposes of the future framework and must not be used elsewhere", immediate. = TRUE)
813-
timeout <- NULL
811+
## FIXME: This should be memoized per plan, when setting up
812+
## the plan /HB 2025-02-18
813+
timeout <- .timeout
814+
815+
if (is.null(timeout)) {
816+
timeout <- getOption("future.cluster.resolved.timeout")
817+
if (is.null(timeout)) {
818+
timeout <- getOption("future.resolved.timeout")
819+
if (is.null(timeout)) {
820+
timeout <- 0.01
821+
}
822+
}
823+
824+
if (timeout < 0) {
825+
warning("Secret option 'future.resolved.timeout' is negative, which causes resolved() to wait until the future is resolved. This feature is only used for testing purposes of the future framework and must not be used elsewhere", immediate. = TRUE)
826+
timeout <- NULL
827+
} else {
828+
.timeout <<- timeout
829+
}
814830
}
815831
}
816832

0 commit comments

Comments
 (0)