Post ATYCd18JZP2ONtXshs by noim@noc.social
 (DIR) More posts by noim@noc.social
 (DIR) Post #ATYCd0VJuNqUQxIjvU by ph1@hachyderm.io
       2023-03-12T17:41:53Z
       
       0 likes, 0 repeats
       
       Whatever happened to generators in #javascript? After they were introduced there were quite a few APIs that used them (koa, all those async flow control doodads), but now I can't think of the last time I saw one in the wild.Were they too confusing to use? Made less necessary by async/await?Does anyone know any good current examples of an API that uses them?
       
 (DIR) Post #ATYCd18JZP2ONtXshs by noim@noc.social
       2023-03-12T20:35:08Z
       
       0 likes, 0 repeats
       
       Fix:@ph1 Async/Await is just more convenient. However, generators still have some use. Here are two examples:- Use in combination with for-await to iterate over a paginated API.- Cancelable calls.Maybe there are even more use cases, but yes, they are rare.
       
 (DIR) Post #ATZlbJOcOAji063NSK by juliangonggrijp@ieji.de
       2023-03-13T14:41:36Z
       
       0 likes, 0 repeats
       
       @noim @ph1 They are a bit niche.- Generating just one value: async/await is easier, as mentioned.- Generating a series: more likely to use events or streams or to just store everything in an array eagerly.Generators do allow lazy patterns, where e.g. you transform and filter a series partially with takeWhile. Lodash attempted to do such a thing before generators existed with "shortcut fusion", which was bloaty and nonscalable. #UnderscoreJS 2.0 will support generators as a collection type.