decorated_future: Create a decorated future.

Description Usage Arguments Details Value Examples

Description

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>.

Usage

1
decorated_future(inner, pre = function() { }, post = function() { })

Arguments

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.

Details

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'.

Value

A decorated future that wraps around 'inner'.

Examples

 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)

wlandau/workers documentation built on May 26, 2019, 6:30 a.m.