node-cassandra-cql
node-cassandra-cql copied to clipboard
How can I handle streams backpressure?
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?
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 :)