Open JosiahParry opened 1 day ago
coro::async()
inherits the properties of promises (https://rstudio.github.io/promises). By default they are scheduled by a top-level event loop that runs when R is idle so only that loop and the tasks it manages (promises including ones created by async functions) have access to values.
In practice this means you can only access values from an async function only from another async context by using await()
.
I think there are ways to create local event loops that allow you to block on a promise (like block_on()
in Rust) but I haven't tried this: https://github.com/r-lib/later/blob/82d9609217fdddb601b1569891f9fcece62a78be/R/later.R#L28
Using a modified example from {coro}, it is unclear how to access the value of the function. Here we return
n
after the async function has completed.Running this results in a promise (expected) however, trying to get the value via
n$finally()
results in an error.At present it seems that using
async()
is intended only for functions with side effects. Is that correct?