1#' A future with a constant value
2#'
3#' A constant future is a future whose expression is a constant
4#' and therefore by definition is already resolved upon creation.
5#'
6#' @inheritParams Future-class
7#'
8#' @return An object of class `ConstantFuture`.
9#'
10#' @export
11#' @name ConstantFuture-class
12#' @keywords internal
13ConstantFuture <- function(..., globals = TRUE, envir = emptyenv()) {
14  future <- Future(..., globals = list(), envir = envir)
15  future$result <- FutureResult(value = eval(future$expr, envir = envir))
16  future$state <- "finished"
17  future <- structure(future, class = c("ConstantFuture", class(future)))
18  future
19}
20
21#' @export
22run.ConstantFuture <- function(future, ...) {
23  future
24}
25
26#' @export
27result.ConstantFuture <- function(future, ...) {
28  future$result
29}