mirror of https://github.com/mattn/go-sqlite3.git
Merge pull request #530 from navytux/y/no-go-if-notneeded
Don't spawn interrupt goroutine if we know that context cannot be canceled
This commit is contained in:
commit
696e2e43cb
|
@ -1124,9 +1124,10 @@ func (s *SQLiteStmt) query(ctx context.Context, args []namedValue) (driver.Rows,
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctxdone := ctx.Done(); ctxdone != nil {
|
||||||
go func(db *C.sqlite3) {
|
go func(db *C.sqlite3) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctxdone:
|
||||||
select {
|
select {
|
||||||
case <-rows.done:
|
case <-rows.done:
|
||||||
default:
|
default:
|
||||||
|
@ -1136,6 +1137,7 @@ func (s *SQLiteStmt) query(ctx context.Context, args []namedValue) (driver.Rows,
|
||||||
case <-rows.done:
|
case <-rows.done:
|
||||||
}
|
}
|
||||||
}(s.c.db)
|
}(s.c.db)
|
||||||
|
}
|
||||||
|
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
@ -1169,12 +1171,13 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctxdone := ctx.Done(); ctxdone != nil {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
defer close(done)
|
defer close(done)
|
||||||
go func(db *C.sqlite3) {
|
go func(db *C.sqlite3) {
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-ctx.Done():
|
case <-ctxdone:
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
default:
|
default:
|
||||||
|
@ -1182,6 +1185,7 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(s.c.db)
|
}(s.c.db)
|
||||||
|
}
|
||||||
|
|
||||||
var rowid, changes C.longlong
|
var rowid, changes C.longlong
|
||||||
rv := C._sqlite3_step(s.s, &rowid, &changes)
|
rv := C._sqlite3_step(s.s, &rowid, &changes)
|
||||||
|
|
Loading…
Reference in New Issue