[HN Gopher] Delimited Generators - A more natural API for JS gen...
       ___________________________________________________________________
        
       Delimited Generators - A more natural API for JS generators
        
       Author : jchanimal
       Score  : 12 points
       Date   : 2024-05-02 14:47 UTC (8 hours ago)
        
 (HTM) web link (axisofeval.blogspot.com)
 (TXT) w3m dump (axisofeval.blogspot.com)
        
       | neals wrote:
       | So what are some issues when working with async/await?
        
         | eyelidlessness wrote:
         | The classic complaint is the "function color" problem;
         | otherwise worded as: async is infectious. Anything that depends
         | on async itself must become async (whether by keyword or by
         | dealing directly with Promise APIs).
         | 
         | There may be other valid issues, but they're a pretty sharp
         | drop off from that first one in most cases that aren't either
         | extremely niche or highly subjective.
        
       | steve_adams_86 wrote:
       | I feel a bit stupid. I use generators a lot, but I don't
       | understand what this offers as a convenience.
       | 
       | Maybe I don't actually understand generators!
       | 
       | Edit: I'm realizing it's that I don't understand delimiting. This
       | is really interesting. I'll have to sit with it for a while for
       | it to click, I think.
       | 
       | I have a feeling a use delimiting patterns with generators
       | already, but I didn't understand it as such.
        
         | neals wrote:
         | What do you use generators for?
        
         | ilaksh wrote:
         | I don't normally use generators. I can't figure out how this
         | syntax or functionality is in any way different from normal
         | generators.
        
       | gabrielsroka wrote:
       | See also
       | 
       | https://exploringjs.com/es6/ch_generators.html
       | 
       | Or was it
       | 
       | https://exploringjs.com/impatient-js/ch_async-iteration.html...
        
       | andrewstuart wrote:
       | Is this a reinvention of async/await?
        
         | eyelidlessness wrote:
         | Not so much a reinvention. Both generators and async functions
         | share the property that they can suspend execution and yield to
         | the event loop. Many early polyfills for async functions
         | utilized generators for that reason.
        
           | andrewstuart wrote:
           | async/await is built on generators.
        
       | agumonkey wrote:
       | oh, reading his previous blog article I see that J. Shutt (he
       | made kernel, reviving fexpr in a way) commented
       | 
       | https://axisofeval.blogspot.com/2011/08/notes-on-delimited-c...
       | 
       | and that he has a blogger (last entry in 2020 though)
       | https://fexpr.blogspot.com/
        
       | mmastrac wrote:
       | This is cool, but hitting break on the single timeout example in
       | Firefox suggests that this code is actually filling the stack up
       | pretty quickly, once per iteration through the loop.
       | 
       | The concept is neat, though: it's basically handing off a number
       | of callbacks. Under the hood I think you'll find that it's just a
       | really expensive version of `Promise.then`.
        
       | orf wrote:
       | I remember being able to do this using Twisted in Python 2.6 or
       | so, using the same techniques.
       | 
       | At the time, the way to manipulate "deferred" results was to use
       | the equivalent of "Promise.then", but using generators as a quasi
       | async/await seemed much more fluid.
       | 
       | I'm not sure what this gives you over actual async/await though,
       | other than being an interesting thing to look at?
        
       ___________________________________________________________________
       (page generated 2024-05-02 23:01 UTC)