dstandish commented on PR #31987:
URL: https://github.com/apache/airflow/pull/31987#issuecomment-1662982115

   If we really want to allow user to do stuff post-yield, and still accept 
only one event, it's possible to do:
   ```python
   async def do_loop_with_stuff_after_yield():
       inner_loops = 0
       while True:
           inner_loops += 1
           print(f"{inner_loops}: before ")
           yield "hi"
           print(f"{inner_loops}: after")
           return
   
   async def main():
       outer_loops = 0
       async for event in do_loop_with_stuff_after_yield():
           outer_loops += 1
           if outer_loops > 1:
               raise RuntimeError("Yielding more than one event is not 
supported.")
           print(outer_loops, ',', event)
   
   asyncio.run(main())
   ```
   
   But were we to do this, I think it would still be possible (though perhaps 
not super likely) that the trigger in question is canceled before it comes 
around to resume the iteration and thus the code between `yield` and `return` 
would not have been run.  As such, it does not seem like something anyone 
should ever do.
   
   Though if we really desired this, we could actually guarantee that the code 
between `yield` and `return` is always run. And the way to do this would be to 
delay adding the event to the `events` deque until after the generator exits.  
But then the event emission would be delayed until the trigger returns, which 
begs the question, why not just delay yielding the event in the first place.
   
   So, there doesn't seem to be much value in running code post yield.  At the 
same time, it is a little weird to just not fully consume the generator that 
the user wrote, and moreover to do so silently.  Curious if @uranusjr might 
have a thought.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to