MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / CommitWith

Method CommitWith

tx.go:102–132  ·  view source on GitHub ↗
(cb func(error))

Source from the content-addressed store, hash-verified

100}
101
102func (tx *Tx) CommitWith(cb func(error)) {
103 if cb == nil {
104 panic("Nil callback provided to CommitWith")
105 }
106
107 if tx.isClosed() {
108 go runTxnCallback(&txnCb{user: cb, err: ErrCannotCommitAClosedTx})
109 return
110 }
111
112 if tx.db == nil {
113 tx.setStatusClosed()
114 go runTxnCallback(&txnCb{user: cb, err: ErrDBClosed})
115 return
116 }
117
118 tx.setStatusCommitting()
119
120 commitCb, err := tx.commitAndSend()
121 if err != nil {
122 tx.handleErr(err)
123 tx.setStatusClosed()
124 tx.unlock()
125 tx.db = nil
126 tx.pendingWrites = nil
127 go runTxnCallback(&txnCb{user: cb, err: err})
128 return
129 }
130
131 go runTxnCallback(&txnCb{user: cb, commit: commitCb})
132}
133
134func (tx *Tx) commitAndSend() (func() error, error) {
135 req, err := tx.db.sendToWriteCh(tx)

Calls 7

isClosedMethod · 0.95
setStatusClosedMethod · 0.95
setStatusCommittingMethod · 0.95
commitAndSendMethod · 0.95
handleErrMethod · 0.95
unlockMethod · 0.95
runTxnCallbackFunction · 0.85