run(expr) with an expression directly writen, will parse that expression as a coroutine, but then run it without pausing.

  type = list(),
  split_pipes = FALSE,
  debugR = FALSE,
  debugInternal = FALSE,
  trace = getOption("async.verbose")



A generator expression, same as you would write in gen.


A value whose mode will determine the output vector mode (as in vapply.)




See async; defaults to FALSE.


Will open a browser at the first and subsequent R evaluations allowing single-stepping through user code.


Will set a breakpoint at the implementation level, allowing single-stepping through async package code.


a tracing function.


If expr contains any yield calls, a vector of the same mode as type; otherwise the return value of expr.


If the expression contains any calls to yield(), run() will collect all the values passed to yield() and return a list. If the expression contains a yield() but it is never called, run() returns an empty list. If the expression does not contain a yield at all, run returns the expression's final return value.

run(expr) is similar to as.list(gen(expr)), except run(expr) evaluates its expression directly in the calling environment, while gen creates a new enclosed environment to run in.

run is useful if you want to take advantage of coroutine language extensions, such as using for loops over iterators, or using goto() in switch statements, in otherwise synchronous code. If you want to collect a variable-length sequence of values but don't need those features, using collect directly will have better performance.


run(type=0, {
  for (i in iterors::iseq(2, Inf, by=5)) {
    if (i %% 37 == 0) break
    else yield(i)
#> [1]  2  7 12 17 22 27 32