package database import ( "context" "database/sql" "git.sdf.org/jchenry/x" ) type Func func(ctx context.Context, db *sql.DB) error type Actor struct { DB *sql.DB ActionChan chan Func } func (a *Actor) Run(ctx context.Context) error { x.Assert(ctx != nil, "Actor.Run: context cannot be nil") for { select { case f := <-a.ActionChan: if err:= f(ctx, a.DB); err != nil{ return err } case <-ctx.Done(): return ctx.Err() } } }