diff --git a/DESCRIPTION b/DESCRIPTION index 4810121896..d32868a3d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -107,6 +107,7 @@ Suggests: reactlog (>= 1.0.0), magrittr, yaml, + mirai, future, dygraphs, ragg, diff --git a/R/bind-cache.R b/R/bind-cache.R index 870ab2f317..013a1db5d4 100644 --- a/R/bind-cache.R +++ b/R/bind-cache.R @@ -231,8 +231,8 @@ utils::globalVariables(".GenericCallEnv", add = TRUE) #' promises, but rather objects provided by the #' \href{https://rstudio.github.io/promises/}{\pkg{promises}} package, which #' are similar to promises in JavaScript. (See [promises::promise()] for more -#' information.) You can also use [future::future()] objects to run code in a -#' separate process or even on a remote machine. +#' information.) You can also use [mirai::mirai()] or [future::future()] +#' objects to run code in a separate process or even on a remote machine. #' #' If the value returns a promise, then anything that consumes the cached #' reactive must expect it to return a promise. diff --git a/R/extended-task.R b/R/extended-task.R index 131251bb94..800b72d358 100644 --- a/R/extended-task.R +++ b/R/extended-task.R @@ -41,12 +41,15 @@ #' is, a function that quickly returns a promise) and allows even that very #' session to immediately unblock and carry on with other user interactions. #' -#' @examplesIf rlang::is_interactive() && rlang::is_installed("future") -#' +#' @examplesIf rlang::is_interactive() && rlang::is_installed("mirai") #' library(shiny) #' library(bslib) -#' library(future) -#' plan(multisession) +#' library(mirai) +#' +#' # Set background processes for running tasks +#' daemons(1) +#' # Reset when the app is stopped +#' onStop(function() daemons(0)) #' #' ui <- page_fluid( #' titlePanel("Extended Task Demo"), @@ -60,13 +63,12 @@ #' #' server <- function(input, output) { #' rand_task <- ExtendedTask$new(function() { -#' future( +#' mirai( #' { #' # Slow operation goes here #' Sys.sleep(2) #' sample(1:100, 1) -#' }, -#' seed = TRUE +#' } #' ) #' }) #' @@ -100,11 +102,12 @@ ExtendedTask <- R6Class("ExtendedTask", portable = TRUE, cloneable = FALSE, #' @param func The long-running operation to execute. This should be an #' asynchronous function, meaning, it should use the #' [\{promises\}](https://rstudio.github.io/promises/) package, most - #' likely in conjuction with the + #' likely in conjunction with the + #' [\{mirai\}](https://mirai.r-lib.org) or #' [\{future\}](https://rstudio.github.io/promises/articles/promises_04_futures.html) #' package. (In short, the return value of `func` should be a - #' [`Future`][future::future()] object, or a `promise`, or something else - #' that [promises::as.promise()] understands.) + #' [`mirai`][mirai::mirai()], [`Future`][future::future()], `promise`, + #' or something else that [promises::as.promise()] understands.) #' #' It's also important that this logic does not read from any #' reactive inputs/sources, as inputs may change after the function is diff --git a/man/ExtendedTask.Rd b/man/ExtendedTask.Rd index ade5334bd8..6f219b866a 100644 --- a/man/ExtendedTask.Rd +++ b/man/ExtendedTask.Rd @@ -46,12 +46,15 @@ session to immediately unblock and carry on with other user interactions. } \examples{ -\dontshow{if (rlang::is_interactive() && rlang::is_installed("future")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} - +\dontshow{if (rlang::is_interactive() && rlang::is_installed("mirai")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(shiny) library(bslib) -library(future) -plan(multisession) +library(mirai) + +# Set background processes for running tasks +daemons(1) +# Reset when the app is stopped +onStop(function() daemons(0)) ui <- page_fluid( titlePanel("Extended Task Demo"), @@ -65,13 +68,12 @@ ui <- page_fluid( server <- function(input, output) { rand_task <- ExtendedTask$new(function() { - future( + mirai( { # Slow operation goes here Sys.sleep(2) sample(1:100, 1) - }, - seed = TRUE + } ) }) @@ -121,11 +123,12 @@ server function. \item{\code{func}}{The long-running operation to execute. This should be an asynchronous function, meaning, it should use the \href{https://rstudio.github.io/promises/}{\{promises\}} package, most -likely in conjuction with the +likely in conjunction with the +\href{https://mirai.r-lib.org}{\{mirai\}} or \href{https://rstudio.github.io/promises/articles/promises_04_futures.html}{\{future\}} package. (In short, the return value of \code{func} should be a -\code{\link[future:future]{Future}} object, or a \code{promise}, or something else -that \code{\link[promises:is.promise]{promises::as.promise()}} understands.) +\code{\link[mirai:mirai]{mirai}}, \code{\link[future:future]{Future}}, \code{promise}, +or something else that \code{\link[promises:is.promise]{promises::as.promise()}} understands.) It's also important that this logic does not read from any reactive inputs/sources, as inputs may change after the function is diff --git a/man/bindCache.Rd b/man/bindCache.Rd index f3df4c4e06..10a2f20f76 100644 --- a/man/bindCache.Rd +++ b/man/bindCache.Rd @@ -234,8 +234,8 @@ With a cached reactive expression, the key and/or value expression can be promises, but rather objects provided by the \href{https://rstudio.github.io/promises/}{\pkg{promises}} package, which are similar to promises in JavaScript. (See \code{\link[promises:promise]{promises::promise()}} for more -information.) You can also use \code{\link[future:future]{future::future()}} objects to run code in a -separate process or even on a remote machine. +information.) You can also use \code{\link[mirai:mirai]{mirai::mirai()}} or \code{\link[future:future]{future::future()}} +objects to run code in a separate process or even on a remote machine. If the value returns a promise, then anything that consumes the cached reactive must expect it to return a promise. diff --git a/man/shiny-package.Rd b/man/shiny-package.Rd index e96daa4b27..33803bd0ae 100644 --- a/man/shiny-package.Rd +++ b/man/shiny-package.Rd @@ -61,7 +61,7 @@ Other contributors: \item John Fraser (showdown.js library) [contributor, copyright holder] \item John Gruber (showdown.js library) [contributor, copyright holder] \item Ivan Sagalaev (highlight.js library) [contributor, copyright holder] - \item R Core Team (tar implementation from R) [contributor, copyright holder] + \item R Core Team (tar implementation from R) [contributor, copyright holder] } }