Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion sequel.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ type Tx struct {
tx *sqlx.Tx
clock clock.Clock
doRebindModel bool
oncommit []func()
}

// Begin begins a transaction and returns a new Tx.
Expand Down Expand Up @@ -441,7 +442,19 @@ func (t *Tx) rebindModel(query string) string {

// Commit commits the transaction.
func (t *Tx) Commit() error {
return t.tx.Commit()
err := t.tx.Commit()
if err != nil {
return err
}
for _, fn := range t.oncommit {
go fn()
}
return nil
}

// PostCommit registers a function to be called asynchronously after a successful commit.
func (t *Tx) PostCommit(fn func()) {
t.oncommit = append(t.oncommit, fn)
}

// Rollback aborts the transaction.
Expand Down