Testing automatic pause/resume in node-mysql Query.stream() in https://github.com/ZJONSSON/node-mysql/commit/eb4410bbc1e4496cbac66fe56f32225e55f7e463
| var stream = require("stream"), | |
| mysql = require("/node-mysql"); | |
| var connection = mysql.createConnection({ | |
| host : 'localhost', | |
| user : 'root' | |
| }); | |
| var query = connection.query("select * from sakila.rental ") | |
| .stream({highWaterMark:5}); | |
| // Simple writable stream that delays 1 sec before console.log and callback(); | |
| // Purpose: test whether the pipe pauses correctly while waiting for write to finish | |
| var testStream = new stream.Writable({highWaterMark: 10, objectMode: true}); | |
| testStream._write = function(chunk,encoding,callback) { | |
| setTimeout(function() { | |
| console.log(chunk); | |
| callback(); | |
| },500); | |
| } | |
| // Pipe the query stream into the testStream | |
| query.pipe(testStream) | |
| // Monitor data events on the side to see when we pause | |
| query.on("result",function(d,i) { | |
| console.log("Received data") | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment