MCPcopy Create free account
hub / github.com/daodst/chat / run

Method run

internal/sqlutil/writer_exclusive.go:59–82  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

57// opened using the database object from the task and then this will
58// be passed as a parameter to the task function.
59func (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}

Callers 1

DoMethod · 0.95

Calls 3

goidFunction · 0.85
WithTransactionFunction · 0.85
DeleteMethod · 0.45

Tested by

no test coverage detected