-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are value-consuming generators useful? #101
Comments
Well, the generator can be made lazy now, so your intuition is probably correct for eager generators, that would do a look ahead. There's probably some niche use-case, but I would agree that it's more likely that pushing values would be used for lazy ones. |
So, it looks to me that at least the recommended practice should be that if you use a push-value generator you always put |
But even the lazy push-value generators: do they have a use case? It does not compile for at least two reasons (unused variable Is there a full example anywhere? I have a feeling that a code that does not use a coroutine would be simpler. In the use case you simply request new things to be serialized. There is nothing being generated. |
The example is missing a The generator can make complex state management easier, because you can put things like the serializer into the generator frame. You need more complexity than that however for that to pay off (which makes bad examples) so I understand your skepticism. I would however also add, that you or I thinking something is simpler doesn't mean that users will agree. Based on my knowledge of other languages I am pretty confident that there are plenty of use cases. Regarding the name: that's just the common name for the same thing in other languages (python, js). To the "should always be lazy point": well that's how python does it. But there you have to |
By "recommended practice" I mean putting a note in docs, "if you are using a push-value generator, you probably want to perform the inirial suspense." |
That wouldn't be enough. It still has a plain
I agree with this argumentation for generators that do not consume values. My criticism is for the ones that consume values. I challenge the example not because of the "size of the maintained state" alone, but because of the combination: "size of the maintained state" and "nothing is generated".
I think that maybe the name is fine but the example is not exemplary of the capabilities of value-consuming generators. I realize that I just dump more work on you (find a better example), but I must admit, I am lacking imagination or intuition in this domain. |
One more observation. Given that:
The design of this library would be simpler if these two were separate coroutine types:
|
The two-argument variant of
async::generator
, one that is able to consume values from the resumer, seems to have no practical use case. At least none has been provided in the docs or examples. I personally question its utility because of the shape of the interface. The coroutine sees it this way:Where a natural reading is that
value_from_resumer
is in response to the yieldedvalue_from_coroutine
. But the resumer sees it this way:Here the resumer has to prepare and inject the value before it asks the coroutine to generate its next value. This is in contradiction to the previous expectation.
I presented my intuition. It may be wrong. But the documentation does not offer any other. I believe that the value consuming interface of
async::generator
should be either removed, or justified in the docs.The text was updated successfully, but these errors were encountered: