42 questions
0
votes
0
answers
80
views
How to create async iterator over callback which calls back multiple times (or a stream) in TypeScript?
How do I get this working in TypeScript? Here is the EventIterator library, which seems to make it possible to build a queue to handle the callbacks of the xhr progress event nicely.
import { ...
1
vote
1
answer
94
views
Why does step-wise async iteration in separate tasks behave differently than without tasks?
I just isolated a strange behavior I've observed, but now I'm out of ideas.
My script asynchronously iterates over the stdout stream of a process which has been spawned via ssh (asyncssh) in a kind of ...
2
votes
0
answers
804
views
How to create a NodeJS Readable Stream from Async Iterable (AWS S3 SelectObjectContentEventStream)?
Problem
I am using @aws-sdk/client-s3 - 3.414.0, and its SelectObjectContentCommand returning an S3 Select result as AsyncIterable<SelectObjectContentEventStream>.
I am trying to then parse this ...
2
votes
0
answers
437
views
How to mock the v3 aws-sdk's paginators?
I'm migrating some old aws-sdk v2 code to the new v3 and found some pretty neat new paginator logic. I wanted to use that but am having trouble unit testing it which is making this process take much ...
-1
votes
2
answers
287
views
splice/shift first n bytes of AsyncIterable<Uint8Array>
reading the first n bytes of a byte stream (in form of a AsyncIterable) feels cumbersome and error prone.
Is there a better way to implement this?
async function shift(
length: number,
stream: ...
0
votes
1
answer
1k
views
trying to select a .csv file from the file input and pass it to the backend and read it from the back end using remix run
I am trying to select a CSV file with some columns and data using file input. This is the content of the CSV
id,level,cvss,title,Vulnerability,Solution,reference, 963,LOW,7.8,Title - 963,Vulnerability ...
1
vote
1
answer
1k
views
Is it safe to create a Python class which is simultaneously sync and async iterator?
Is it safe/bad practice to make a class both iterator and async iterator? Example:
import asyncio
class Iter:
def __init__(self):
self.i = 0
self.elems = list(range(10))
...
6
votes
4
answers
2k
views
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 ...
2
votes
1
answer
2k
views
Asyncio yielding results from multiple futures as they arrive
I currently have a function, which yields results from an external source, which may arrive over a long time period.
async def run_command(data):
async with httpx.AsyncClient() as client:
...
1
vote
2
answers
567
views
How can you use the Deno.watchFs infinite async iterable without blocking?
So Deno has a filesystem watcher API that seems... obtuse to me. Perhaps that's simply due to my ignorance of async iterators. It's shown to be used like so:
const watcher = Deno.watchFs("/...
1
vote
1
answer
908
views
How do you map PubSub value of a GraphQL subscription in Apollo?
I'm making a GraphQL backend in Apollo, and I'd like to use subscriptions. I followed Apollo's docs, and I've gotten basic subscriptions working using graphql-subscriptions. This package also comes ...
3
votes
1
answer
768
views
Apollo graphQL Server subscription initial response
I've successfully got graphQL subscriptions to work with help of the documentation.
The subscription returns a pubsub.asyncIterator("MY_TOPIC"), which I then can send messages trough.
Now I ...
1
vote
2
answers
8k
views
JavaScript async sleep function somehow leads to silent exiting of program
I copied an async sleep function from here https://stackoverflow.com/a/39914235/7492244
Then I used it basically in this program. https://nodejs.org/api/readline.html#example-read-file-stream-line-by-...
3
votes
1
answer
286
views
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 ...
4
votes
1
answer
2k
views
How is the return method used in iterators / async iterators?
MDN states that async iterators have a return method
const asyncIterable = {
[Symbol.asyncIterator]() {
let i = 0;
return {
next() {
const done = i === LIMIT;
const ...
3
votes
1
answer
703
views
Async iterators with fp-ts and mongo db
With mongodb in node we can use async iterators. Basic example:
const documents: Record<string, any>[] = [];
let cursor = db.collection('randomcollection').find();
for await (let doc of cursor) ...
10
votes
4
answers
6k
views
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 ...
0
votes
1
answer
1k
views
Subscription field must return Async Iterable. Received: undefined
I use graphql nodejs with apollo-server.
When i try i got this error:
I already i returns pubsub.asyncIterator in resolver.
It returns error. Another project same setting works but there it is not ...
1
vote
0
answers
276
views
How to convert async generator to Array in JavaScript? [duplicate]
I'm looking for a way, using build in function if that's possible, to convert async generator into array in JavaScript.
Example that work with generator:
function* foo() { for (let x = 0; x < ...
1
vote
0
answers
127
views
I have a question about the source, 'multipelx async iterator' of Deno standard library
What is purpose of iteratorCount in the following code (from https://deno.land/[email protected]/async/mux_async_iterator.ts)?
#iteratorCount = 0
#yields = []
#throws = []
#signal = deferred()
add () {
++...
7
votes
3
answers
3k
views
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 ...
4
votes
1
answer
3k
views
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.
...
0
votes
0
answers
540
views
Avoid exiting a for-await loop when using asyn iterators
I am using this library https://www.npmjs.com/package/event-iterator to use async iterators. I have the following function
export function grpcClientReadableStreamToAsyncIterator<T>(
stream: ...
5
votes
3
answers
4k
views
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 ...
1
vote
1
answer
78
views
Async iterators and generators: Streaming GeoJSONL
I'm trying to replicate Brett Camper's code about streaming GeoJSONL files, and it is quite complex.
I'm trying to understand what it does step by step, but I really can't figure out what this syntax ...
1
vote
0
answers
951
views
Unhandled Rejection (TypeError): Invalid attempt to iterate non-iterable instance
I'm studying Async iterators and generators from this wonderful page, but when I try to use the following "simple" code...
// Note the * after "function"
async function* asyncRandomNumbers() {
...
1
vote
0
answers
117
views
How can I create a Readable that pipes to a Writable and that will allow me to add content to it from time to time?
What I want to do is probably easy, but after working on this for awhile the implementation that I came up with is a little complicated.
This is what I want to do: I want to be able to create a ...
3
votes
3
answers
2k
views
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(...
7
votes
2
answers
5k
views
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:
...
3
votes
1
answer
18k
views
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....
0
votes
1
answer
691
views
Is there any directory walker in ts / js using an async iterator?
I found plenty of walkers on npm but none is using an asynchronous iterator.
Most of them are either using a callback or a promise leading to memory leaks on huge directories.
Is there any recent ...
1
vote
4
answers
4k
views
Does the Node.js "request" library support an async-iterable response stream?
I'm somewhat new to Node.js libraries and I'm trying figure how to use async iteration over an HTTP response stream. My overall goal is to read a large response stream and process it as chunks arrive,...
8
votes
3
answers
8k
views
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 ...
1
vote
1
answer
251
views
How to *reopen* AsyncIterator after broke a "for await" loop?
In the function testMultipleLoops2 after the first for await,
l will turn to GeneratorStatus:<closed>,
I've done huge research but didn't find a method to reopen it.
const tryRecursive=...
1
vote
1
answer
100
views
A curried function that filters by symbol is unable to get a compatible function implementation in Typescript
I've got a curried batching function that returns an Iterable. If you call it with a sync Iterable you get a sync Iterable, if you give an AsyncIterable you get an AsyncIterable. But can't for the ...
0
votes
1
answer
647
views
How to use a prisma graphql subscription in node app
I am following this guide. I am trying to listen to a graphQL subscription in my node app. I am having a lot of trouble implementing that subscription. I have a tried a few different ways, listed ...
4
votes
1
answer
2k
views
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 ...
1
vote
1
answer
614
views
How to refactor simple for-await-of loop?
I'm playing with some new JavaScript features like async/await and generators. I have function readPages with signature
async function* readPages(....): AsyncIterableIterator<string> {}
and I ...
0
votes
0
answers
112
views
Real world examples of asynchronous iterators usage
I would like to know some possible real world usage examples of asynchronous iterators, part of ECMAScript 2018.
For readable streams it looks useful, since we would be able to iterate them easily ...
2
votes
2
answers
2k
views
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 ...
2
votes
1
answer
1k
views
Is there a way to implement <T>(x: Promise<AsyncIterableIterator<T>>): AsyncIterableIterator<T> in TypeScript?
So I get Promise<AsyncIterableIterator<T>> and I need plain AsyncIterableIterator<T> how can I unwrap the AsyncIterableIterator<T> from under the promise?
6
votes
3
answers
2k
views
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 ...