Skip to content

Commit c396646

Browse files
Add with(<plan>, <expression>)
1 parent 54e59fe commit c396646

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future
2-
Version: 1.34.0-9301
2+
Version: 1.34.0-9302
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Imports:
55
digest,

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ S3method(value,Future)
8686
S3method(value,environment)
8787
S3method(value,list)
8888
S3method(value,listenv)
89+
S3method(with,FutureStrategyList)
8990
export("%->%")
9091
export("%<-%")
9192
export("%conditions%")

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
on having to specify globals and packages, not having conditions
1616
and standard output relayed, and ignoring random number generation.
1717

18+
* Add `with(<plan>, <expression>)` method to evaluate an expression,
19+
including futures, using a temporary future plan.
20+
1821
## Bug Fixes
1922

2023
* Now 'interrupt' conditions are captured during the evaluation of

R/utils_api-with.R

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#' Evaluate an expression using a temporarily set future plan
2+
#'
3+
#' @param data The future plan to use temporarily.
4+
#'
5+
#' @param The R expression to be evaluated.
6+
#'
7+
#' @param \ldots Not used.
8+
#'
9+
#' @return The value of the expression evaluated.
10+
#'
11+
#' @example incl/with.R
12+
#'
13+
#' @export
14+
with.FutureStrategyList <- function(data, expr, ...) {
15+
on.exit(plan(data))
16+
plan("next")
17+
expr
18+
}

incl/with.R

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Evaluate a future using the 'multisession' plan
2+
with(plan(multisession, workers = 2), {
3+
f <- future(Sys.getpid())
4+
w_pid <- value(f)
5+
c(main = Sys.getpid(), worker = w_pid)
6+
})
7+

man/with.FutureStrategyList.Rd

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)