Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Access value of promise from async() function #61

@JosiahParry

Description

@JosiahParry

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.

async_count_down <- coro::async(function(n) {
  while (n > 0) {
    cat("Down", n, "\n")
    coro::await(coro::async_sleep(1))
    n <- n - 1
  }
  n
})

n <- async_count_down()

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions