Testing automatic pause/resume in node-mysql Query.stream() in https://github.com/ZJONSSON/node-mysql/commit/eb4410bbc1e4496cbac66fe56f32225e55f7e463
Last active
December 15, 2015 19:59
-
-
Save ZJONSSON/5314920 to your computer and use it in GitHub Desktop.
Node-mysql Query.stream test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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