Description Usage Arguments Details Value Examples
A decorated future is a wrapper that assigns pre-work and post-work to an existing inner future. For more on futures, visit <https://github.com/HenrikBengtsson/future>.
1 | decorated_future(inner, pre = function() { }, post = function() { })
|
inner |
The original future that the decorated future wraps around. |
pre |
A function, the pre-work to be executed on the master process before the inner future. |
post |
A function, the post-work to be executed on the master process after the inner future. |
When the scheduler executes a decorated future, the pre-work defined in 'pre' runs on the master process, and then the inner future runs. When the scheduler collects a decorated future, it checks that the inner future is resolved and then does the post-work defined in 'post'.
A decorated future that wraps around 'inner'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ## Not run:
success <- function() {
future::future(list(success = TRUE))
}
x <- 1
delayed_future <- future.callr::callr({
Sys.sleep(1)
list(success = TRUE)
})
decorated_future <- decorated_future(
delayed_future,
post = function() {
x <<- x + 2
}
)
code <- list(
a = function() {
decorated_future
},
b = function() {
x <<- x * 3; success()
}
)
vertices <- tibble::tibble(name = letters[1:2], code)
edges <- tibble::tibble(from = "a", to = "b")
graph <- igraph::graph_from_data_frame(edges, vertices = vertices)
schedule(graph)
print(x) # Should be 9.
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.