You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lazy futures: Specify how/when globals are resolved? #1
## A global variablea<-0f<- lazy({
42*a
})
## Since 'a' is a global variable in _lazy_ future 'f',## which still hasn't been resolved, any changes to## 'a' until 'f' is resolved, will affect its value.a<-1v<- value(f)
print(v)
stopifnot(v==42)
Proposal
Should there be an option to specify when globals in lazy futures should be resolved, e.g.
The purpose of this would mostly be to (i) illustrate the importance of understanding how globals are handled, and (ii) provide a lazy future mechanism that as far as possible emulated what happens when evaluating futures in external processes/R sessions.
To add this, we also need to add dependency on the globals package.
Will hold this one of for a while, because if introduced it would also add dependency on globals and that might be too specific for other needs. It's possible that a better strategy is to keep this outside of this package and leave it to the specific "Future" packages downstream.
will calculate convergence counts for the exact same (=the last one) complex plane for all iterations, because the globals are only resolved when evaluated. Globals needs to be "frozen" (exported) for each future.
Fibonacci series
The following example for illustrating futures, does not work with current "lazy" implementation, because all future iterations end up using the same value on iterator variable i (=50) when resolved:
See commit f65a767. Added lazy(..., globals=TRUE), which is also the default. Updated tests, examples and demos accordingly.
This only provides a mechanism for including ("freezing") globals for lazy future, and eager futures don't need it. If it turns out it is useful to provide an automatic mechanism for this in future(), then it can be added in a future release. If so, then open a new issue on this topic.
Activity
HenrikBengtsson commentedon Jun 12, 2015
Will hold this one of for a while, because if introduced it would also add dependency on
globalsand that might be too specific for other needs. It's possible that a better strategy is to keep this outside of this package and leave it to the specific "Future" packages downstream.HenrikBengtsson commentedon Jun 16, 2015
Some arguments for having 'future' handle globals too:
Mandelbrot demo
will calculate convergence counts for the exact same (=the last one) complex plane for all iterations, because the globals are only resolved when evaluated. Globals needs to be "frozen" (exported) for each future.
Fibonacci series
The following example for illustrating futures, does not work with current "lazy" implementation, because all future iterations end up using the same value on iterator variable
i(=50) when resolved:HenrikBengtsson commentedon Jun 16, 2015
See commit f65a767. Added
lazy(..., globals=TRUE), which is also the default. Updated tests, examples and demos accordingly.This only provides a mechanism for including ("freezing") globals for lazy future, and eager futures don't need it. If it turns out it is useful to provide an automatic mechanism for this in
future(), then it can be added in a future release. If so, then open a new issue on this topic.DEMO: Now canvas is labelled with 'Future #1 unresolved', ...