Comments (5)
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.
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.
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.
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.
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)
- Make things more relatable by explaining synonyms
- I am confused between promiseBuffer.iterator.next(value) and promiseBuffer.generator.yield(value) HOT 4
- Why are variables `done: false`? HOT 4
- Minor typos, clarity tweaks, and suggestions HOT 1
- Discuss the `on` operator proposed by Jafar
- How to create "pull streams"? HOT 4
- Visual modelling HOT 1
- CSP channels HOT 16
- Byte stream behavior HOT 1
- Interesting use of tasks HOT 1
- Describe pressure relief strategies
- Typo HOT 1
- Off by one error in echo example HOT 5
- Asynchronous Generator Functions: Link to Jafar Husain's document prompts for permission HOT 3
- Suggestion: Use the term “channel” for publishers and subscribers HOT 7
- Announcement: Live presentations upcoming HOT 17
- Make this into a GitBook? HOT 6
- Tests are failing HOT 1
- MediterraneaJS link do dot work
- Talk about the issue of generator objects and their relation to function calls?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gtor.