new db package with actor
This commit is contained in:
parent
3cedd8564c
commit
fcc302dcfe
24
db/actor.go
Normal file
24
db/actor.go
Normal file
@ -0,0 +1,24 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Func func(db *sql.DB)
|
||||
|
||||
type Actor struct {
|
||||
DB *sql.DB
|
||||
ActionChan chan Func
|
||||
}
|
||||
|
||||
func (a *Actor) Run(ctx context.Context) error {
|
||||
for {
|
||||
select {
|
||||
case f := <-a.ActionChan:
|
||||
f(a.DB)
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user