x/database/actor.go

25 lines
306 B
Go
Raw Normal View History

package database
2020-06-10 16:04:25 -07:00
import (
"context"
"database/sql"
)
type Func func(db *sql.DB)
type Actor struct {
DB *sql.DB
2020-09-04 20:24:37 -07:00
ActionChan chan Func
2020-06-10 16:04:25 -07:00
}
func (a *Actor) Run(ctx context.Context) error {
for {
select {
case f := <-a.ActionChan:
f(a.DB)
case <-ctx.Done():
return ctx.Err()
}
}
}