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

Add support for Generator and AsyncGenerator #31

Open
lxsmnsyc opened this issue Nov 18, 2023 · 11 comments
Open

Add support for Generator and AsyncGenerator #31

lxsmnsyc opened this issue Nov 18, 2023 · 11 comments

Comments

@lxsmnsyc
Copy link
Owner

No description provided.

@ducan-ne
Copy link

Hi @lxsmnsyc I see this already implemented in code but is that not flagged ready to use?

Try to use it with solid start but seem like doesn't work

export const logHello = async function (message: string) {
  'use server'
  console.log(message)

  return {
    title: 'Hello World',
    async* [Symbol.asyncIterator](): AsyncIterator<number> {
      await Promise.resolve()
      yield 1
      await new Promise((resolve) => setTimeout(resolve, 1000))
      yield 2
      await new Promise((resolve) => setTimeout(resolve, 5000))
      yield 3
    },
  }
}
export const logHello = async function * (message: string) {
  "use server";
  console.log(message);

  yield { a: true }
  await new Promise((resolve) => setTimeout(resolve, 5000))

  yield { b: true }
};

@lxsmnsyc
Copy link
Owner Author

@ducan-ne Last time I've tested this this should work. Please provide more info.

@ducan-ne
Copy link

ducan-ne commented May 14, 2024

@lxsmnsyc
The lastest version should show catch the error
https://github.com/ducan-ne/solid-async-generator-reproduction/blob/main/src/actions.tsx
https://github.com/ducan-ne/solid-async-generator-reproduction/blob/main/src/components/Counter.tsx

for await (const value of logHello('Hello')) { not work either

Error

Uncaught (in promise) TypeError: logHello(...) is not a function or its return value is not async iterable

Or

Counter.tsx:20  Uncaught (in promise) {a: true}

This is my first time tried solid start so I'm not sure it's right way to use generator, but that's how we use it js

@lxsmnsyc
Copy link
Owner Author

lxsmnsyc commented May 14, 2024

Okay I've tested this one, this isn't a Seroval problem. Please create an issue in SolidStart.

I intend to clean up this thread since it merits its own issue thread.

@ducan-ne
Copy link

Okay, thank for your infromation

@theturtle32
Copy link

This functionality works just fine for me in SolidStart.

@lxsmnsyc
Copy link
Owner Author

@theturtle32 are we talking about the last comment or the entire concept

@theturtle32
Copy link

The entire concept works fine for me.

@theturtle32
Copy link

I use server functions with async generators to return chunks of streaming chat-bot responses from the server to the client via seroval.

@theturtle32
Copy link

And it appears that the related bug in SolidStart was closed as completed on May 20th.

@lxsmnsyc
Copy link
Owner Author

lxsmnsyc commented Aug 17, 2024

@theturtle32 yep it's been resolved. This topic is originally for the full support of Generators and AsyncGenerators (this also includes the yield) but got sidetracked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants