Skip to content

Commit e753bdd

Browse files
committed
Make transaction commit and rollback return standard promises
1 parent 8d88bbc commit e753bdd

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/transaction.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ class Transaction {
107107
this._state = committed.state
108108
// clean up
109109
this._onClose()
110-
return committed.result
110+
return new Promise((resolve, reject) => {
111+
committed.result.subscribe({
112+
onCompleted: () => resolve(),
113+
onError: error => reject(error)
114+
})
115+
})
111116
}
112117

113118
/**
@@ -118,15 +123,20 @@ class Transaction {
118123
* @returns {Result} New Result
119124
*/
120125
rollback () {
121-
let committed = this._state.rollback({
126+
let rolledback = this._state.rollback({
122127
connectionHolder: this._connectionHolder,
123128
onError: this._onError,
124129
onComplete: this._onComplete
125130
})
126-
this._state = committed.state
131+
this._state = rolledback.state
127132
// clean up
128133
this._onClose()
129-
return committed.result
134+
return new Promise((resolve, reject) => {
135+
rolledback.result.subscribe({
136+
onCompleted: () => resolve(),
137+
onError: error => reject(error)
138+
})
139+
})
130140
}
131141

132142
/**

test/transaction.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import neo4j from '../src'
2020
import sharedNeo4j from './internal/shared-neo4j'
2121
import { ServerVersion } from '../src/internal/server-version'
22+
import TxConfig from '../src/internal/tx-config'
2223

2324
describe('#integration transaction', () => {
2425
let driver
@@ -571,6 +572,20 @@ describe('#integration transaction', () => {
571572
})
572573
})
573574

575+
it('should return empty promise on commit', async () => {
576+
const tx = session.beginTransaction()
577+
const result = await tx.commit()
578+
579+
expect(result).toBeUndefined()
580+
})
581+
582+
it('should return empty promise on rollback', async () => {
583+
const tx = session.beginTransaction()
584+
const result = await tx.rollback()
585+
586+
expect(result).toBeUndefined()
587+
})
588+
574589
function expectSyntaxError (error) {
575590
expect(error.code).toBe('Neo.ClientError.Statement.SyntaxError')
576591
}

0 commit comments

Comments
 (0)