Skip to content

Instantly share code, notes, and snippets.

@storkme
Created February 3, 2015 22:29
Show Gist options
  • Save storkme/dfac8b1e9980278365c1 to your computer and use it in GitHub Desktop.
Save storkme/dfac8b1e9980278365c1 to your computer and use it in GitHub Desktop.
Sample with Rx.Observable.using and node-mysql connection pooling
var source = Rx.Observable.using(
() => {
var conn,
disposable = Rx.Observable.fromNodeCallback(this.pool.getConnection, this.pool)()
.doOnNext((connection) => {
conn = connection
});
disposable.dispose = () => {
if (conn) {
conn.release();
}
};
return disposable;
},
(futureConnection) => {
return futureConnection
.selectMany((conn) => {
//perform some query with the conn object.
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment