Questions tagged [async-iterator]
42 questions
7
votes
3 answers
Why does this readline async iterator not work properly?
This is part of a larger process that I've distilled down to the minimal, reproducible example in node v14.4.0. In this code, it outputs nothing from inside the for loop.
I see only this output in the console:
before for()…

jfriend00
- 683,504
- 96
- 985
- 979
7
votes
3 answers
Using javascript's Symbol.asyncIterator with for await of loop
I am trying to understand javascript's Symbol.asyncIterator and for await of. I wrote some simple code and it throws an error saying:
TypeError: undefined is not a function
on the line which tries to use for await (let x of a).
I could not…

Suhail Gupta
- 22,386
- 64
- 200
- 328
5
votes
3 answers
Convert function using callbacks into Async Iterator variant
Scenario
I'm given a function with an asynchronous callback like
let readFile: (path: string, callback: (line: string, eof: boolean) => void) => void
Though I would prefer a function using AsyncIterable/AsyncGenerator signature instead:
let…

Mal
- 355
- 2
- 8
5
votes
3 answers
Async Generator: Yielding a rejected promise
I've been playing around with async generators in an attempt to make a "promise ordering" generator which takes an array of promises and yields out promises one by one in the order they resolve or reject. So something like:
async function*…

CRice
- 29,968
- 4
- 57
- 70
5
votes
2 answers
How to handle error from fs readline.Interface async iterator
Based on the example of processLineByLine() I noticed that we cannot catch the error if the given filename does not exist. In that case the program finishes with something like:
UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or…

Miguel Gamboa
- 8,855
- 7
- 47
- 94
4
votes
3 answers
How to map over async generators?
Let's say we have an async generator:
exports.asyncGen = async function* (items) {
for (const item of items) {
const result = await someAsyncFunc(item)
yield result;
}
}
is it possible to map over this generator? Essentially I want to…

Dmitry Kankalovich
- 553
- 2
- 8
- 19
4
votes
1 answer
Calling a function that returns a AsyncIterableIterator without using "for await" block
I'm writing an AWS Lambda function in TypeScript using the Node.js runtime. I'm using a "batchDelete" function from a DynamoDB ORM library which returns an AsyncIterableIterator type.
According to the documentation here…

Gambit
- 286
- 3
- 8
4
votes
1 answer
what happens to uniterated async iterators?
Say I have the following function
async def f1():
async for item in asynciterator():
return
What happens to the async iterator after
await f1()
? Should I worry about cleaning up or will the generator be somehow garbage collected when…

Liviu
- 1,023
- 2
- 12
- 33
3
votes
1 answer
How to use AsyncGenerators with Kotlin/JS?
I'm currently trying to use IPFS with Kotlin/JS, though my problem isn't specific to that.
The ipfs.cat() and ipfs.get() functions return an AsyncGenerator and I'm unsure how to iterate over it with Kotlin (I'm not even sure which type would best…

Minmo
- 143
- 3
- 6
3
votes
1 answer
Async iterators with fp-ts and mongo db
With mongodb in node we can use async iterators. Basic example:
const documents: Record[] = [];
let cursor = db.collection('randomcollection').find();
for await (let doc of cursor) {
documents.push(document);
}
How does async…

florian norbert bepunkt
- 2,099
- 1
- 21
- 32
3
votes
1 answer
Use AsyncIterator in Typescript – required options
Consider this basic AsyncIterator Example from MDN:
var asyncIterable = {
[Symbol.asyncIterator]() {
return {
i: 0,
next() {
if (this.i < 3) {
return Promise.resolve({ value: this.i++, done: false });
}
…

panepeter
- 3,224
- 1
- 29
- 41
3
votes
3 answers
How can I find out if a javascript iterator terminates early?
Lets say I have a generator:
function* source() {
yield "hello"; yield "world";
}
I create the iterable, iterate with a for-loop, and then break out of the loop before the iterator fully completes (returns done).
function run() {
for (let…

Meirion Hughes
- 24,994
- 12
- 71
- 122
2
votes
1 answer
Parallel asynchronous iteraor - is it possible?
Right now I have the following code:
import axios from 'axios'
const urls = ['https://google.com', 'https://yahoo.com']
async function* requests() {
for (const url of urls) {
yield axios.get(url)
}
}
;(async () => {
for await (const n…
user11845830
2
votes
2 answers
After installing graphql-tools and graphql-express. Error message in console 'Cannot find name 'AsyncIterator'
Error Log On initiating application
While initiating the application it shows the following error and i tried couple of fixes from online which has mentioned below but none of them has worked requesting for suggestions and solutions…

Rigin Oommen
- 3,060
- 2
- 20
- 29
2
votes
1 answer
Is there a way to implement (x: Promise>): AsyncIterableIterator in TypeScript?
So I get Promise> and I need plain AsyncIterableIterator how can I unwrap the AsyncIterableIterator from under the promise?

Trident D'Gao
- 18,973
- 19
- 95
- 159