# 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
})
Run the code above in your browser using DataLab