async-iterator

Is there any directory walker in ts / js using an async iterator?

别来无恙 提交于 2021-02-11 14:57:22
问题 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 library using the following pattern: async function* walk(dirPath) { // some magic… yield filePath; } To then use it like: for await (const filePath of walk('/dir/path')) { console.log('file path', filePath); } 回答1: Okay, I simply made this walker using the synchronous readdir, it is very fast and

Async Generator: Yielding a rejected promise

◇◆丶佛笑我妖孽 提交于 2021-02-07 21:54:23
问题 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* orderProms(prom_arr) { // Make a copy so the splices don't mess it up. const proms = [...prom_arr]; while (proms.length) { // Tag each promise with it's index, so that we can remove it for the next loop. const {prom, index} = await Promise.race(proms.map(

How to handle error from fs readline.Interface async iterator

守給你的承諾、 提交于 2020-12-15 05:25:25
问题 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 directory So the most simpler approach that I followed to raise a catchable error was to make 2 modifications to the processLineByLine() function: turn it in a generator such as function* await on file exist check await access(filename, fs.constants.F_OK

How to handle error from fs readline.Interface async iterator

本秂侑毒 提交于 2020-12-15 05:24:20
问题 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 directory So the most simpler approach that I followed to raise a catchable error was to make 2 modifications to the processLineByLine() function: turn it in a generator such as function* await on file exist check await access(filename, fs.constants.F_OK

Why does this readline async iterator not work properly?

有些话、适合烂在心里 提交于 2020-12-10 07:33:12
问题 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() loop finished finally done The for await (const line1 of rl1) loop never goes into the for loop - it just skips right over it: const fs = require('fs'); const readline = require('readline'); const { once } = require('events'); async function test(file1, file2) { try { const

After installing graphql-tools and graphql-express. Error message in console 'Cannot find name 'AsyncIterator'

眉间皱痕 提交于 2019-12-11 13:36:49
问题 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 node_modules/@types/graphql/subscription/subscribe.d.ts(17,12): error TS2304: Cannot find name 'AsyncIterator'. node_modules/@types/graphql/subscription/subscribe.d.ts(29,12): error TS2304: Cannot find name 'AsyncIterable'. node_modules/graphql-tools/dist