rstudio / promises

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

$then should check that input is a function #42

Open wch opened 5 years ago

wch commented 5 years ago

The then() function gives an error when a non-functionable object is passed to it:

promise_resolve("start") %>%
  then("then") %>%
  then(function(value) { message(value) })
#> Unhandled promise error: Don't know how to convert object of class character into a promise

However the $then() method doesn't give an error. I'm not sure what it's doing:

promise_resolve("start")$
  then("then")$
  then(function(value) { message(value) })
#> start
jcheng5 commented 5 years ago

I think I was just being extremely conservative with the R6 interface and sticking to the JS promise spec, which specifies that non function arguments are no-ops. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then

Doesn't seem like a helpful policy, I agree...