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

Method Do

internal/sqlutil/writer_exclusive.go:38–53  ·  view source on GitHub ↗

Do queues a task to be run by a TransactionWriter. The function provided will be ran within a transaction as supplied by the txn parameter if one is supplied, and if not, will take out a new transaction from the database supplied in the database parameter. Either way, this will block until the task

(db *sql.DB, txn *sql.Tx, f func(txn *sql.Tx) error)

Source from the content-addressed store, hash-verified

36// new transaction from the database supplied in the database
37// parameter. Either way, this will block until the task is done.
38func (w *ExclusiveWriter) Do(db *sql.DB, txn *sql.Tx, f func(txn *sql.Tx) error) error {
39 if w.todo == nil {
40 return errors.New("not initialised")
41 }
42 if !w.running.Load() {
43 go w.run()
44 }
45 task := transactionWriterTask{
46 db: db,
47 txn: txn,
48 f: f,
49 wait: make(chan error, 1),
50 }
51 w.todo <- task
52 return <-task.wait
53}
54
55// run processes the tasks for a given transaction writer. Only one
56// of these goroutines will run at a time. A transaction will be

Callers

nothing calls this directly

Calls 2

runMethod · 0.95
LoadMethod · 0.80

Tested by

no test coverage detected