@@ -22,7 +22,7 @@ UniprocessFuture <- function(expr = NULL, substitute = TRUE, envir = parent.fram
2222# ' @export
2323run.UniprocessFuture <- function (future , ... ) {
2424 debug <- isTRUE(getOption(" future.debug" ))
25-
25+
2626 if (future [[" state" ]] != ' created' ) {
2727 label <- future [[" label" ]]
2828 if (is.null(label )) label <- " <none>"
@@ -105,3 +105,74 @@ SequentialFuture <- function(expr = NULL, envir = parent.frame(), substitute = T
105105 f <- UniprocessFuture(expr = expr , envir = envir , substitute = FALSE , lazy = lazy , globals = globals , ... )
106106 structure(f , class = c(" SequentialFuture" , class(f )))
107107}
108+
109+
110+
111+ launchFuture <- function (backend , future , ... ) {
112+ UseMethod(" launchFuture" )
113+ }
114+
115+ # ' @export
116+ launchFuture.SequentialFutureBackend <- function (backend , future , ... ) {
117+ debug <- isTRUE(getOption(" future.debug" ))
118+ if (debug ) {
119+ mdebugf(" launchFuture() for %s ..." , commaq(class(backend )))
120+ on.exit(mdebugf(" launchFuture() for %s ... DONE" , commaq(class(backend ))))
121+ }
122+
123+ if (future [[" state" ]] != ' created' ) {
124+ label <- future [[" label" ]]
125+ if (is.null(label )) label <- " <none>"
126+ stop(FutureError(sprintf(" A future ('%s') can only be launched once" , label ), future = future ))
127+ }
128+
129+ # # Assert that the process that created the future is
130+ # # also the one that evaluates/resolves/queries it.
131+ assertOwner(future )
132+
133+ # # Coerce to a SequentialFuture
134+ # # NOTE: Has to be done before getFutureData() is called
135+ class(future ) <- c(" SequentialFuture" , " UniprocessFuture" , class(future ))
136+
137+ # # Launch future
138+ future [[" state" ]] <- " running"
139+
140+ # # Get future
141+ data <- getFutureData(future , debug = debug )
142+
143+ # # Apply backend tweaks
144+ split <- backend [[" split" ]]
145+ if (! is.null(split )) data $ capture $ split <- split
146+ earlySignal <- backend [[" earlySignal" ]]
147+ if (! is.null(earlySignal )) future $ earlySignal <- earlySignal
148+
149+ future [[" result" ]] <- evalFuture(data )
150+
151+ future [[" state" ]] <- " finished"
152+
153+ if (debug ) mdebugf(" %s started (and completed)" , class(future )[1 ])
154+
155+ # # Always signal immediateCondition:s and as soon as possible.
156+ # # They will always be signaled if they exist.
157+ signalImmediateConditions(future )
158+
159+ # # Signal conditions early, iff specified for the given future
160+ signalEarly(future , collect = FALSE )
161+
162+ future
163+ }
164+
165+ SequentialFutureBackend <- function (... ) {
166+ core <- new.env(parent = emptyenv())
167+
168+ # # Record future plan tweaks, if any
169+ args <- list (... )
170+ for (name in names(args )) {
171+ core [[name ]] <- args [[name ]]
172+ }
173+
174+ core <- structure(core , class = c(" SequentialFutureBackend" , " FutureBackend" , class(core )))
175+
176+ core
177+ }
178+
0 commit comments