rstudio / promises

A promise library for R
https://rstudio.github.io/promises
Other
198 stars 19 forks source link

How to use promise in if-conditional? #21

Open boxiangliu opened 6 years ago

boxiangliu commented 6 years ago

Suppose I want to execute something based on the result of a promise, how could I use the promise in a if-conditional? Thank you!

jcheng5 commented 6 years ago

If I understand you correctly, you'd put the if-conditional in the promise handler.

async_random <- function() {
  promise_resolve(runif(1))
}

async_random() %...>% (function(val) {
  if (val < 0.5)
    print("less than")
  else
    print("greater than")
})