diff --git a/DESCRIPTION b/DESCRIPTION index 42db0249..05573a18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mirai Type: Package Title: Minimalist Async Evaluation Framework for R -Version: 1.3.1.9017 +Version: 1.3.1.9018 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 diff --git a/NEWS.md b/NEWS.md index e2ebe338..e239f859 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# mirai 1.3.1.9017 (development) +# mirai 1.3.1.9018 (development) #### Architecture Change diff --git a/R/dispatcher.R b/R/dispatcher.R index 55191d27..9e20e05d 100644 --- a/R/dispatcher.R +++ b/R/dispatcher.R @@ -160,16 +160,13 @@ dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL, found <- TRUE break } - if (found) { - found <- NA - } else { + if (!found) for (i in seq_along(inq)) if (inq[[i]][["msgid"]] == id) { inq[[i]] <- NULL found <- TRUE break } - } send(ctx, found, mode = 2L, block = TRUE) } else { status <- c( diff --git a/R/mirai.R b/R/mirai.R index 767228a0..103815b7 100644 --- a/R/mirai.R +++ b/R/mirai.R @@ -391,19 +391,22 @@ collect_mirai <- collect_aio #' Stops a \sQuote{mirai} if still in progress, causing it to resolve #' immediately to an \sQuote{errorValue} 20 (Operation canceled). #' -#' In the case that the \sQuote{mirai} is in execution and an interrupt was -#' sent, the task or a portion of it may have completed before the interrupt is -#' received, and even then it is not always possible to immediately interrupt -#' evaluation (especially if it is compiled code). +#' Using dispatcher allows cancellation of \sQuote{mirai}. In the case that the +#' \sQuote{mirai} is awaiting execution, it is discarded from the queue and +#' never evaluated. In the case it is already in execution, an interrupt will be +#' sent. A successful cancellation request does not guarantee successful +#' cancellation. Note that the task, or a portion of it, may have already +#' completed before the interrupt is received. Even then it is not always +#' possible to immediately interrupt, for example, compiled code. This should be +#' noted particularly if the code carries out side effects during execution, +#' such as writing to files, etc. #' #' @inheritParams call_mirai #' -#' @return A logical value: \code{TRUE} if the cancellation request was -#' definitely successful (task was awaiting execution and has been discarded), -#' \code{NA} if a cancellation request was successfully sent (task was in -#' execution, and will be interrupted), and \code{FALSE} if already completed -#' or previously cancelled. Will always return \code{FALSE} if not using -#' dispatcher. +#' @return Logical \code{TRUE} if the cancellation request was successful (was +#' awaiting execution or in execution), or else \code{FALSE} (if already +#' completed or previously cancelled). Will always return \code{FALSE} if not +#' using dispatcher. #' #' @examples #' if (interactive()) { diff --git a/man/stop_mirai.Rd b/man/stop_mirai.Rd index 4bde0d91..3749fde0 100644 --- a/man/stop_mirai.Rd +++ b/man/stop_mirai.Rd @@ -10,22 +10,25 @@ stop_mirai(x) \item{x}{a \sQuote{mirai} object, or list of \sQuote{mirai} objects.} } \value{ -A logical value: \code{TRUE} if the cancellation request was - definitely successful (task was awaiting execution and has been discarded), - \code{NA} if a cancellation request was successfully sent (task was in - execution, and will be interrupted), and \code{FALSE} if already completed - or previously cancelled. Will always return \code{FALSE} if not using - dispatcher. +Logical \code{TRUE} if the cancellation request was successful (was + awaiting execution or in execution), or else \code{FALSE} (if already + completed or previously cancelled). Will always return \code{FALSE} if not + using dispatcher. } \description{ Stops a \sQuote{mirai} if still in progress, causing it to resolve immediately to an \sQuote{errorValue} 20 (Operation canceled). } \details{ -In the case that the \sQuote{mirai} is in execution and an interrupt was -sent, the task or a portion of it may have completed before the interrupt is -received, and even then it is not always possible to immediately interrupt -evaluation (especially if it is compiled code). +Using dispatcher allows cancellation of \sQuote{mirai}. In the case that the +\sQuote{mirai} is awaiting execution, it is discarded from the queue and +never evaluated. In the case it is already in execution, an interrupt will be +sent. A successful cancellation request does not guarantee successful +cancellation. Note that the task, or a portion of it, may have already +completed before the interrupt is received. Even then it is not always +possible to immediately interrupt, for example, compiled code. This should be +noted particularly if the code carries out side effects during execution, +such as writing to files, etc. } \examples{ if (interactive()) { diff --git a/tests/tests.R b/tests/tests.R index 54022a55..1857d52c 100644 --- a/tests/tests.R +++ b/tests/tests.R @@ -274,7 +274,7 @@ connection && Sys.getenv("NOT_CRAN") == "true" && { m2 <- mirai({ Sys.sleep(1); res <<- "m2 done" }) Sys.sleep(0.1) test_true(stop_mirai(m2)) - test_true(is.na(stop_mirai(m1))) + test_true(stop_mirai(m1)) test_equal(m2$data, 20L) test_equal(m1$data, 20L) test_class("errorValue", mirai(res)[])