Giter VIP home page Giter VIP logo

Comments (5)

kriskowal avatar kriskowal commented on August 17, 2024

This asymmetry has been bothering me as well, but I have been asking myself the opposite question, what does it mean for the consumer to return? Perhaps that question can be answered if I study what it means for generators now. I am skeptical if it means that the yield behaves like a return.

from gtor.

domenic avatar domenic commented on August 17, 2024

Well, from what I can tell, (sync) generators are a complete free-for-all in terms of capabilities vended; the consumer can do the exact same set of operations that the producer can, just using methods instead of syntax.

from gtor.

kriskowal avatar kriskowal commented on August 17, 2024

Yeah, sync and async generator objects should probably be symmetric, and they would be completely symmetric if we renamed "next" to "yield" (not going to happen, but perhaps for the purposes of a completely ivory tower blog…)

from gtor.

kriskowal avatar kriskowal commented on August 17, 2024

I added return to the iterator interface in both the article and the stream sketch, but perhaps you or @andywingo can do me a favor and illuminate what happens when you iterator.return(10) on a generator that is paused on a yield. Throwing on a yield makes sense to me. Does it turn the yield into a return, unravelling the stack and forcing the generator to terminate with the given return value? When the stack passes through a try/catch, I assume it bypasses the catch, but if it passes through a try/finally, I presume it executes the finally. If the finally has a yield or return, I presume it overrides the intended return 10 iteration, leaving the generator in a resumable state if it yields.

from gtor.

wingo avatar wingo commented on August 17, 2024

WRT your question, I don't really know yet what return means, as it hasn't reached the spec yet. I think your idea is right but who knows; specification is magical.

from gtor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.