Skip to content
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

Generator functions #35

Closed
Ayc0 opened this issue Jun 20, 2018 · 4 comments · May be fixed by #50
Closed

Generator functions #35

Ayc0 opened this issue Jun 20, 2018 · 4 comments · May be fixed by #50
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Ayc0
Copy link

Ayc0 commented Jun 20, 2018

Is it possible to support generator functions in addition to async functions?

@developit
Copy link
Owner

Yes, and I really want to get this supported!

If you or anyone coming across this wants to try implementing it in Greenlet, I'd be delighted to work with you to get it merged.

@developit developit added enhancement New feature or request help wanted Extra attention is needed labels Aug 27, 2018
@DCtheTall
Copy link
Contributor

I'd be happy to take a swing at this.

I assume it will always return an instance of a AsyncGeneratorFunction?

@developit
Copy link
Owner

Whoops, sorry for the slow reply! Yes this would coerce the main thread to an async generator, regardless of whether it is synchronous or asynchronous.

johnsonjo4531 added a commit to johnsonjo4531/greenlet that referenced this issue Dec 28, 2019
fixes developit#35

tldr; Mainly wrapped the existing promise api to get it to work
with async generators.
I took atleast two iterations to get to this point. At first I thought
to do the job with a readable Stream implementing async iterable
on the main thread, but then was afraid of inconsistencies that
would arise between the two apis. For example Readable Stream
when finished will only return `{ done: true, value: undefined }`
whereas async iterables can return `{ done: true, value: any }`
when `any` is any value.

So, then I decided to make a async generator that could talk to
the worker for better compatibility. One thing to note is that the worker
data onmessage receives an extra piece for the status to cause the
iterator to use. This is similar to the Promise status, but for
generators.
@johnsonjo4531
Copy link
Contributor

@Ayc0 @DCtheTall @developit hey, I made an attempt at this. Feel free to review. Hope you don't mind I took a shot at it 😅. I just was thinking about how useful this could be, and I also wanted to try and use it in a project, so I was hoping it would come sooner rather than later!

@Ayc0 Ayc0 closed this as completed Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants