We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f568b61 commit 3759d1cCopy full SHA for 3759d1c
1 file changed
sequel.go
@@ -412,6 +412,7 @@ type Tx struct {
412
tx *sqlx.Tx
413
clock clock.Clock
414
doRebindModel bool
415
+ oncommit []func()
416
}
417
418
// Begin begins a transaction and returns a new Tx.
@@ -441,7 +442,19 @@ func (t *Tx) rebindModel(query string) string {
441
442
443
// Commit commits the transaction.
444
func (t *Tx) Commit() error {
- return t.tx.Commit()
445
+ err := t.tx.Commit()
446
+ if err != nil {
447
+ return err
448
+ }
449
+ for _, fn := range t.oncommit {
450
+ go fn()
451
452
+ return nil
453
+}
454
+
455
+// PostCommit registers a function to be called asynchronously after a successful commit.
456
+func (t *Tx) PostCommit(fn func()) {
457
+ t.oncommit = append(t.oncommit, fn)
458
459
460
// Rollback aborts the transaction.
0 commit comments