@@ -30,19 +30,25 @@ class Transaction {
3030 * @param {Promise } connectionPromise - A connection to use
3131 * @param {function() } onClose - Function to be called when transaction is committed or rolled back.
3232 * @param errorTransformer callback use to transform error
33+ * @param bookmark optional bookmark
3334 */
34- constructor ( connectionPromise , onClose , errorTransformer ) {
35+ constructor ( connectionPromise , onClose , errorTransformer , bookmark , onBookmark ) {
3536 this . _connectionPromise = connectionPromise ;
3637 let streamObserver = new _TransactionStreamObserver ( this ) ;
38+ let params = { } ;
39+ if ( bookmark ) {
40+ params = { bookmark : bookmark } ;
41+ }
3742 this . _connectionPromise . then ( ( conn ) => {
3843 streamObserver . resolveConnection ( conn ) ;
39- conn . run ( "BEGIN" , { } , streamObserver ) ;
44+ conn . run ( "BEGIN" , params , streamObserver ) ;
4045 conn . discardAll ( streamObserver ) ;
4146 } ) . catch ( streamObserver . onError ) ;
4247
4348 this . _state = _states . ACTIVE ;
4449 this . _onClose = onClose ;
4550 this . _errorTransformer = errorTransformer ;
51+ this . _onBookmark = onBookmark || ( ( ) => { } ) ;
4652 }
4753
4854 /**
@@ -114,6 +120,14 @@ class _TransactionStreamObserver extends StreamObserver {
114120 this . _hasFailed = true ;
115121 }
116122 }
123+
124+ onCompleted ( meta ) {
125+ super . onCompleted ( meta ) ;
126+ let bookmark = meta . bookmark ;
127+ if ( bookmark ) {
128+ this . _tx . _onBookmark ( bookmark ) ;
129+ }
130+ }
117131}
118132
119133/** internal state machine of the transaction*/
0 commit comments