Created
February 3, 2015 22:29
-
-
Save storkme/dfac8b1e9980278365c1 to your computer and use it in GitHub Desktop.
Sample with Rx.Observable.using and node-mysql connection pooling
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 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