consul: Adding Defer to MDBTxn
This commit is contained in:
parent
a1b59bcaf9
commit
2e3d3ec2f8
|
@ -63,6 +63,7 @@ type MDBTxn struct {
|
||||||
readonly bool
|
readonly bool
|
||||||
tx *mdb.Txn
|
tx *mdb.Txn
|
||||||
dbis map[string]mdb.DBI
|
dbis map[string]mdb.DBI
|
||||||
|
after []func()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abort is used to close the transaction
|
// Abort is used to close the transaction
|
||||||
|
@ -74,7 +75,19 @@ func (t *MDBTxn) Abort() {
|
||||||
|
|
||||||
// Commit is used to commit a transaction
|
// Commit is used to commit a transaction
|
||||||
func (t *MDBTxn) Commit() error {
|
func (t *MDBTxn) Commit() error {
|
||||||
return t.tx.Commit()
|
if err := t.tx.Commit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, f := range t.after {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
t.after = nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defer is used to defer a function call until a successful commit
|
||||||
|
func (t *MDBTxn) Defer(f func()) {
|
||||||
|
t.after = append(t.after, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
type IndexFunc func(*MDBIndex, []string) string
|
type IndexFunc func(*MDBIndex, []string) string
|
||||||
|
|
Loading…
Reference in New Issue