run processes the tasks for a given transaction writer. Only one of these goroutines will run at a time. A transaction will be opened using the database object from the task and then this will be passed as a parameter to the task function.
()
| 57 | // opened using the database object from the task and then this will |
| 58 | // be passed as a parameter to the task function. |
| 59 | func (w *ExclusiveWriter) run() { |
| 60 | if !w.running.CAS(false, true) { |
| 61 | return |
| 62 | } |
| 63 | if tracingEnabled { |
| 64 | gid := goid() |
| 65 | goidToWriter.Store(gid, w) |
| 66 | defer goidToWriter.Delete(gid) |
| 67 | } |
| 68 | |
| 69 | defer w.running.Store(false) |
| 70 | for task := range w.todo { |
| 71 | if task.db != nil && task.txn != nil { |
| 72 | task.wait <- task.f(task.txn) |
| 73 | } else if task.db != nil && task.txn == nil { |
| 74 | task.wait <- WithTransaction(task.db, func(txn *sql.Tx) error { |
| 75 | return task.f(txn) |
| 76 | }) |
| 77 | } else { |
| 78 | task.wait <- task.f(nil) |
| 79 | } |
| 80 | close(task.wait) |
| 81 | } |
| 82 | } |
no test coverage detected