@@ -30,19 +30,25 @@ class Transaction {
30
30
* @param {Promise } connectionPromise - A connection to use
31
31
* @param {function() } onClose - Function to be called when transaction is committed or rolled back.
32
32
* @param errorTransformer callback use to transform error
33
+ * @param bookmark optional bookmark
33
34
*/
34
- constructor ( connectionPromise , onClose , errorTransformer ) {
35
+ constructor ( connectionPromise , onClose , errorTransformer , bookmark , onBookmark ) {
35
36
this . _connectionPromise = connectionPromise ;
36
37
let streamObserver = new _TransactionStreamObserver ( this ) ;
38
+ let params = { } ;
39
+ if ( bookmark ) {
40
+ params = { bookmark : bookmark } ;
41
+ }
37
42
this . _connectionPromise . then ( ( conn ) => {
38
43
streamObserver . resolveConnection ( conn ) ;
39
- conn . run ( "BEGIN" , { } , streamObserver ) ;
44
+ conn . run ( "BEGIN" , params , streamObserver ) ;
40
45
conn . discardAll ( streamObserver ) ;
41
46
} ) . catch ( streamObserver . onError ) ;
42
47
43
48
this . _state = _states . ACTIVE ;
44
49
this . _onClose = onClose ;
45
50
this . _errorTransformer = errorTransformer ;
51
+ this . _onBookmark = onBookmark || ( ( ) => { } ) ;
46
52
}
47
53
48
54
/**
@@ -114,6 +120,14 @@ class _TransactionStreamObserver extends StreamObserver {
114
120
this . _hasFailed = true ;
115
121
}
116
122
}
123
+
124
+ onCompleted ( meta ) {
125
+ super . onCompleted ( meta ) ;
126
+ let bookmark = meta . bookmark ;
127
+ if ( bookmark ) {
128
+ this . _tx . _onBookmark ( bookmark ) ;
129
+ }
130
+ }
117
131
}
118
132
119
133
/** internal state machine of the transaction*/
0 commit comments