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

Is there any way to stop the response using this lib? #131

Open
ukicomputers opened this issue Aug 9, 2024 · 1 comment
Open

Is there any way to stop the response using this lib? #131

ukicomputers opened this issue Aug 9, 2024 · 1 comment

Comments

@ukicomputers
Copy link

Hi! Thanks for great library! Is there any way to stop the response using this lib? We are low on resources, so we want when user clicks stop button on our frontend (or closes the page) to stop generating response. We've tried this, but it didn't end the response flow:

try {
    for await (const part of response) {
      if (clientDisconnected) {
        break; // Stop sending data if the client disconnects
      }
      res.write(`${JSON.stringify(part)}`);
    }
  } catch (err) {
    console.error('Error while streaming response:', err);
  } finally {
    console.log("Response ended");
    res.end();
  }

Thanks in advance!

@hopperelec
Copy link
Contributor

Yes, you can either abort all ongoing request (see any request example) or you can abort a specific request (see specific request example)

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

2 participants