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

Compare to coro package #3

Closed
king-of-poppk opened this issue Jun 13, 2023 · 4 comments
Closed

Compare to coro package #3

king-of-poppk opened this issue Jun 13, 2023 · 4 comments

Comments

@king-of-poppk
Copy link

There is a package on CRAN named coro that seems to implement essentially the same primitives on top of the promises package. What are the differences between that package and the async package?

@crowding
Copy link
Owner

crowding commented Jun 13, 2023

  1. async objects print a bit more state information (showing you where they are paused)

  2. async::gen generators are cross compatible with the older R iterators protocol (as used by e.g. the foreach package), and companion package iterors includes a lot of tools to work with them.

  3. the await() method includes an error argument, which allows you to handle promise errors with less boilerplate than using tryCatch.

  4. channels/streams (asynchronous iterators.) Currently I'm working on expanding channels to work with non-blocking connection objects, which will be nice for networking and parallel computing applications.

  5. While not yet completed, the 1.0 release of async will include a compiler, that should improve performance by >10x at least.

@king-of-poppk
Copy link
Author

king-of-poppk commented Jun 14, 2023

Cool! What about interoperability with the future and promises packages?

PS: OK, sorry, interoperability is there, just had to read the README.

@king-of-poppk
Copy link
Author

Another related question: does async suffer the same issue as r-lib/coro#39 ?

@crowding
Copy link
Owner

async() constructs a promise object, and the argument to await can be anything for which an as.promise method is defined, including Future.

The other question is touched on in the language vignette.
async and stream objects always wind on a top-level tryCatch, so any errors during execution should result in promise rejections.
(Generator objects on the other hand will let errors raise to the caller of nextElem).

> f <- async(function() {stop("oops!")})
pr <- f(); pr |> then(\() print("resolved!"), \() print("rejected"))
Warning message:
In cps_translate(expr_, async_endpoints, split_pipes = split_pipes) :
  no keywords (break, next, return, for, switch, goto, on.exit, await, awaitNext) used?
> [1] "rejected"
> pr
async({
    stop("oops!")
})
<environment: R_EmptyEnv>
<async [rejected at `pump__doExits`: <simpleError in eval(val, targetEnv): oops!>]>
<Promise [rejected: simpleError]>

(The warning message is complaining that async(stop()) is kind of pointless because it doesn't have any await calls.)

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

No branches or pull requests

2 participants