Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use promise domain to manage graphics devices #669

Merged
merged 15 commits into from
Sep 11, 2020
Merged

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Sep 9, 2020

# plumber.R

library(promises)
#' @serializer png
#' @get /plot
function(n = 100) {
  dt <- runif(n)
  hist(dt)
  dt
}
# ------------------------------------
#' @serializer png
#' @get /promise_plot1
function(n = 100) {
  promise(function(resolve, reject) {
    later::later(~ resolve(runif(n)), delay = 3)
  }) %...>% {
    dt <- .
    hist(dt)
  }
}

#' @serializer png
#' @get /promise_plot2
function(n = 100) {
  promise(function(resolve, reject) {
    later::later(~ resolve(runif(n)), delay = 3)
  }) %...>% {
    dt <- .
    plot(dt)
  }
}

Visit /promise_plot1 and then quickly visit /promise_plot2 before /promise_plot1 has resolved. Before the PR, this would cause an error and /promise_plot2 would display the plot for /promise_plot1. After this PR, there is no error and the images as expected.

PR task list:

  • Update NEWS
  • Add tests
  • Update documentation with devtools::document()

@cpsievert cpsievert marked this pull request as ready for review September 11, 2020 18:50
@cpsievert cpsievert self-requested a review September 11, 2020 19:01
* master:
  Add peer dependency which npm does not install by default (#670)
@schloerke
Copy link
Collaborator Author

The windows error above is a false positive. xfun could not be installed. I'm guessing it was recently updated and the url failed

@schloerke schloerke merged commit 0b4b5b1 into master Sep 11, 2020
@schloerke schloerke deleted the async-graphics-device branch September 11, 2020 19:26
schloerke added a commit that referenced this pull request Sep 11, 2020
* master:
  Use promise domain to manage graphics devices (#669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants