Redmage/api/lock.go
Tigor Hutasuhut 1896839664
Some checks failed
/ push (push) Has been cancelled
api: use app level lock when writing to database
because of database locked error
2024-05-23 13:49:37 +07:00

14 lines
313 B
Go

package api
// lockf is a helper function to ensure to
// stop other goroutines from accessing the
// same resources at the same time.
//
// e.g. Use this function to wrap any write
// database calls to avoid `database locked error`
func (api *API) lockf(f func()) {
api.mu.Lock()
defer api.mu.Unlock()
f()
}