future (version 1.0.1)

future: Create a future

Description

Creates a future from an expression and returns it. The state of the future is either unresolved or resolved. When it becomes resolved, at some point in the future, its value can be retrieved.

Usage

future(expr, envir = parent.frame(), substitute = TRUE, evaluator = plan(), ...)
futureCall(FUN, args = NULL, envir = parent.frame(), evaluator = plan(), ...)

Arguments

expr
envir
The environment from where global objects should be identified. Depending on "evaluator", it may also be the environment in which the expression is evaluated.
substitute
If TRUE, argument expr is substitute():ed, otherwise not.
evaluator
The actual function that evaluates expr and returns a future. The evaluator function should accept all the same arguments as this function (except evaluator).
FUN
A function object.
args
A list of arguments passed to function FUN.
...
Additional arguments passed to the "evaluator".

Value

A Future.

See Also

It is recommended that the evaluator is non-blocking (returns immediately), but it is not required. The default evaluator function is eager(), but this can be changed via plan() function.

Examples

Run this code
## Use lazy futures
plan(lazy)

f <- future({
  a <- 7
  b <- 3
  c <- 2
  a * b * c
})

print(resolved(f))
y <- value(f)
print(y)

Run the code above in your browser using DataLab