insertControlProgramDelayed takes a template builder and an account control program that hasn't been inserted to the database yet. It registers callbacks on the TemplateBuilder so that all of the template's account control programs are batch inserted if building the rest of the template is successfu
(ctx context.Context, b *txbuilder.TemplateBuilder, acp *controlProgram)
| 212 | // account control programs are batch inserted if building the rest of |
| 213 | // the template is successful. |
| 214 | func (m *Manager) insertControlProgramDelayed(ctx context.Context, b *txbuilder.TemplateBuilder, acp *controlProgram) { |
| 215 | m.delayedACPsMu.Lock() |
| 216 | m.delayedACPs[b] = append(m.delayedACPs[b], acp) |
| 217 | m.delayedACPsMu.Unlock() |
| 218 | |
| 219 | b.OnRollback(func() { |
| 220 | m.delayedACPsMu.Lock() |
| 221 | delete(m.delayedACPs, b) |
| 222 | m.delayedACPsMu.Unlock() |
| 223 | }) |
| 224 | b.OnBuild(func() error { |
| 225 | m.delayedACPsMu.Lock() |
| 226 | acps := m.delayedACPs[b] |
| 227 | delete(m.delayedACPs, b) |
| 228 | m.delayedACPsMu.Unlock() |
| 229 | |
| 230 | // Insert all of the account control programs at once. |
| 231 | if len(acps) == 0 { |
| 232 | return nil |
| 233 | } |
| 234 | return m.insertAccountControlProgram(ctx, acps...) |
| 235 | }) |
| 236 | } |
no test coverage detected