Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 6, 2023
1 parent 324ddaa commit eae1179
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 4 additions & 6 deletions R/parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ make_cluster <- function(n, url = NULL, remote = NULL, ...) {
length(url) == 1L || stop(.messages[["single_url"]])
cv2 <- cv()
daemons(url = url, remote = remote, dispatcher = FALSE, resilience = FALSE, cleanup = FALSE, ..., .compute = id)
envir <- ..[[id]]

if (length(remote)) {
args <- remote[["args"]]
Expand All @@ -110,23 +109,23 @@ make_cluster <- function(n, url = NULL, remote = NULL, ...) {
if (missing(n)) n <- 1L
is.numeric(n) || stop(.messages[["numeric_n"]])
cat("Shell commands for deployment on nodes:\n\n", file = stdout())
print(launch_remote(rep(envir[["urls"]], n), .compute = id))
print(launch_remote(rep(..[[id]][["urls"]], n), .compute = id))
}

} else {
is.numeric(n) || stop(.messages[["numeric_n"]])
cv2 <- cv()
daemons(n = n, dispatcher = FALSE, resilience = FALSE, cleanup = FALSE, ..., .compute = id)
envir <- ..[[id]]
}

envir <- ..[[id]]
envir[["cv2"]] <- cv2
envir[["swapped"]] <- FALSE
pipe_notify(envir[["sock"]], cv = envir[["cv"]], remove = TRUE, flag = TRUE)

cl <- vector(mode = "list", length = n)
for (i in seq_along(cl))
cl[[i]] <- `attributes<-`(new.env(), list(class = "miraiNode", node = i, id = id))
cl[[i]] <- `attributes<-`(new.env(hash = FALSE, parent = emptyenv()), list(class = "miraiNode", node = i, id = id))

`attributes<-`(cl, list(class = c("miraiCluster", "cluster"), id = id))

Expand Down Expand Up @@ -201,8 +200,7 @@ recvOneData.miraiCluster <- function(cl) {
print.miraiCluster <- function(x, ...) {

id <- attr(.subset2(x, 1L), "id")
cat(sprintf("< miraiCluster >\n - cluster ID: %s\n - nodes: %d\n - active: %s\n",
id, length(x), as.logical(length(..[[id]]))), file = stdout())
cat(sprintf("< miraiCluster >\n - cluster ID: %s\n - nodes: %d\n - active: %s\n", id, length(x), as.logical(length(..[[id]]))), file = stdout())
invisible(x)

}
Expand Down
4 changes: 1 addition & 3 deletions R/promises.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ as.promise.mirai <- function(x)
query <- function()
if (unresolved(x))
later(query, delay = 0.1) else
if (is_error_value(value <- .subset2(x, "value")))
reject(value) else
resolve(value)
if (is_error_value(value <- .subset2(x, "value"))) reject(value) else resolve(value)
query()
}
)

0 comments on commit eae1179

Please sign in to comment.