Skip to content

Commit

Permalink
fold legacy dispatcher into dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 3, 2024
1 parent ad214f7 commit 81e9238
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 108 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mirai
Type: Package
Title: Minimalist Async Evaluation Framework for R
Version: 1.3.1.9015
Version: 1.3.1.9016
Description: Designed for simplicity, a 'mirai' evaluates an R expression
asynchronously in a parallel process, locally or distributed over the
network, with the result automatically available upon completion. Modern
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export(collect_mirai)
export(daemon)
export(daemons)
export(dispatcher)
export(dispatcher_v1)
export(everywhere)
export(host_url)
export(is_error_value)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mirai 1.3.1.9015 (development)
# mirai 1.3.1.9016 (development)

#### Architecture Change

Expand Down
8 changes: 4 additions & 4 deletions R/daemon.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ daemon <- function(url, ..., dispatcher = FALSE, asyncdial = FALSE, autoexit = T
cleanup = TRUE, output = FALSE, tls = NULL, rs = NULL) {

dispatcher || return(
ddaemon(
daemon_legacy(
url = url, asyncdial = asyncdial, autoexit = autoexit, cleanup = cleanup,
output = output, ..., tls = tls, rs = rs
)
Expand Down Expand Up @@ -146,9 +146,9 @@ daemon <- function(url, ..., dispatcher = FALSE, asyncdial = FALSE, autoexit = T

}

ddaemon <- function(url, asyncdial = FALSE, autoexit = TRUE, cleanup = TRUE,
output = FALSE, maxtasks = Inf, idletime = Inf, walltime = Inf,
timerstart = 0L, ..., tls = NULL, rs = NULL) {
daemon_legacy <- function(url, asyncdial = FALSE, autoexit = TRUE, cleanup = TRUE,
output = FALSE, maxtasks = Inf, idletime = Inf, walltime = Inf,
timerstart = 0L, ..., tls = NULL, rs = NULL) {

cv <- cv()
sock <- socket(protocol = "rep")
Expand Down
4 changes: 2 additions & 2 deletions R/daemons.R
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,13 @@ wa32 <- function(url, dots, rs, tls = NULL)
shQuote(sprintf("mirai::daemon(\"%s\"%s%s,rs=c(%s),dispatcher=TRUE)", url, dots, parse_tls(tls), paste0(rs, collapse = ",")))

wa4 <- function(urld, dots, rs, n, urlc)
shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher_v1(\"%s\",n=%d,rs=c(%s),monitor=\"%s\"%s)", libp(), urld, n, paste0(rs, collapse= ","), urlc, dots))
shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",n=%d,rs=c(%s),monitor=\"%s\"%s)", libp(), urld, n, paste0(rs, collapse= ","), urlc, dots))

wa42 <- function(urld, dots, rs, n)
shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",n=%d,rs=c(%s)%s)", libp(), urld, n, paste0(rs, collapse= ","), dots))

wa5 <- function(urld, dots, n, urlc, url)
shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher_v1(\"%s\",c(\"%s\"),n=%d,monitor=\"%s\"%s)", libp(), urld, paste0(url, collapse = "\",\""), n, urlc, dots))
shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",c(\"%s\"),n=%d,monitor=\"%s\"%s)", libp(), urld, paste0(url, collapse = "\",\""), n, urlc, dots))

wa52 <- function(urld, dots, url)
shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",url=\"%s\"%s)", libp(), urld, url, dots))
Expand Down
35 changes: 10 additions & 25 deletions R/dispatcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@
#' @param pass [default NULL] (required only if the private key supplied to
#' \sQuote{tls} is encrypted with a password) For security, should be provided
#' through a function that returns this value, rather than directly.
#' @param monitor unused legacy parameter - do not specify this value.
#'
#' @return Invisible NULL.
#'
#' @export
#'
dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL, rs = NULL) {
dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL,
rs = NULL, monitor = NULL) {

missing(monitor) || return(
dispatcher_legacy(
host = host, url = url, n = n, ..., tls = tls, pass = pass, rs = rs, monitor = monitor
)
)
n <- if (is.numeric(n)) as.integer(n) else length(url)
n > 0L || stop(._[["missing_url"]])

Expand Down Expand Up @@ -205,30 +212,8 @@ dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL,

}

#' Dispatcher (v1)
#'
#' This is a deprecated legacy function only present to support existing uses.
#'
#' @inheritParams dispatcher
#' @param retry [default FALSE] logical value, whether to automatically retry
#' tasks where the daemon crashes or terminates unexpectedly on the next
#' daemon instance to connect. If TRUE, the mirai will remain unresolved but
#' \code{\link{status}} will show \sQuote{online} as 0 and \sQuote{assigned} >
#' \sQuote{complete}. To cancel a task in this case, use
#' \code{saisei(force = TRUE)}. If FALSE, such tasks will be returned as
#' \sQuote{errorValue} 19 (Connection reset).
#' @param token [default FALSE] if TRUE, appends a unique 24-character token to
#' each URL path the dispatcher listens at (not applicable for TCP URLs which
#' do not accept a path).
#' @param monitor (for package internal use only) do not set this parameter.
#'
#' @return Invisible NULL.
#'
#' @keywords internal
#' @export
#'
dispatcher_v1 <- function(host, url = NULL, n = NULL, ..., retry = FALSE, token = FALSE,
tls = NULL, pass = NULL, rs = NULL, monitor = NULL) {
dispatcher_legacy <- function(host, url = NULL, n = NULL, ..., retry = FALSE,
token = FALSE, tls = NULL, pass = NULL, rs = NULL, monitor = NULL) {

n <- if (is.numeric(n)) as.integer(n) else length(url)
n > 0L || stop(._[["missing_url"]])
Expand Down
13 changes: 12 additions & 1 deletion man/dispatcher.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 0 additions & 73 deletions man/dispatcher_v1.Rd

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ connection && .Platform[["OS.type"]] != "windows" && {
test_identical(call_mirai(mp)[["x"]][["data"]], "ab")
test_true(all(mirai_map(data.frame(1:3, 3:1), sum, .args = list(3L))[.flat] == 7L))
test_true(all(mirai_map(list(c(a = 1, b = 1, c = 1), 3), sum)[.flat] == 3))
test_zero(daemons(0L))
}
# parallel cluster tests
library(parallel)
Expand Down Expand Up @@ -224,6 +225,7 @@ connection && .Platform[["OS.type"]] != "windows" && Sys.getenv("NOT_CRAN") == "
test_equal(daemons()[["connections"]], 2L)
test_type("list", res <- mirai_map(c(1,1), rnorm)[.progress])
test_true(res[[1L]] != res[[2L]])
test_zero(daemons(0L))
}
# TLS tests
connection && Sys.getenv("NOT_CRAN") == "true" && {
Expand Down

0 comments on commit 81e9238

Please sign in to comment.