View source: R/iterator-collect.R
async_collect | R Documentation |
async_collect()
takes an asynchronous iterator, i.e. an iterable
function that is also awaitable. async_collect()
returns an
awaitable that eventually resolves to a list containing the values
returned by the iterator. The values are collected until exhaustion
unless n
is supplied. The collection is grown geometrically for
performance.
async_collect(x, n = NULL)
x |
An iterator function. |
n |
The number of elements to collect. If |
# Emulate an async stream by yielding promises that resolve to the
# elements of the input vector
generate_stream <- async_generator(function(x) for (elt in x) yield(elt))
# You can await `async_collect()` in an async function. Once the
# list of values is resolved, the async function resumes.
async(function() {
stream <- generate_stream(1:3)
values <- await(async_collect(stream))
values
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.