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

How can I handle streams backpressure? #116

Open
idandagan1 opened this issue Sep 22, 2020 · 1 comment
Open

How can I handle streams backpressure? #116

idandagan1 opened this issue Sep 22, 2020 · 1 comment

Comments

@idandagan1
Copy link

Hi,
Let's say I have an express app and I'd like to use streams.

For example:

const express = require('express');
const app = express();

app.use((req, res, next) => {
  client.stream('SELECT time, val FROM temperature WHERE station_id=', [ 'abc' ])
    .on('readable', () => {
      let row;
      while (row = this.read()) {
         res.write(row); // THIS SHOULD BE PIPED
      }
    })
    .on('end', function () {})
    .on('error', function (err) {});
})

So in Node.js v10.0.0, they added support for pipeline which uses the benefits of pipe for automatic pause/resume logic - but also forwarding errors and properly cleaning up streams if needed.

How can I handle backpressure?

@bitcloud
Copy link
Contributor

bitcloud commented Sep 23, 2020

Express itself hast a streaming api as well. I guess if you use that you are already covered?

app.use((req, res, next) => {
  client.stream('SELECT time, val FROM temperature WHERE station_id=', [ 'abc' ]).pipe(res);
});

haven't tried it, but i guess it should work :)

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