Skip to content

Commit 3913668

Browse files
author
Aleksander Mogilko
committed
cancellation small refactoring
1 parent e34d751 commit 3913668

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er
177177
return response, cursor, err
178178
case <-ctx.Done():
179179
if q.Type != p.Query_STOP {
180-
stopQuery := formStopQuery(q.Token)
180+
stopQuery := newStopQuery(q.Token)
181181
c.Query(c.contextFromConnectionOpts(), stopQuery)
182182
}
183183
return nil, nil, ErrQueryTimeout

cursor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (c *Cursor) Close() error {
148148

149149
// Stop any unfinished queries
150150
if !c.finished {
151-
_, _, err = conn.Query(c.ctx, formStopQuery(c.token))
151+
_, _, err = conn.Query(c.ctx, newStopQuery(c.token))
152152
}
153153

154154
if c.releaseConn != nil {

query.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,7 @@ func (t Term) Run(s QueryExecutor, optArgs ...RunOpts) (*Cursor, error) {
338338
var ctx context.Context = nil // if it's nil connection will form context from connection opts
339339
if len(optArgs) >= 1 {
340340
opts = optArgs[0].toMap()
341-
if optArgs[0].Context != nil {
342-
ctx = optArgs[0].Context
343-
}
341+
ctx = optArgs[0].Context
344342
}
345343

346344
if s == nil || !s.IsConnected() {
@@ -450,9 +448,7 @@ func (t Term) Exec(s QueryExecutor, optArgs ...ExecOpts) error {
450448
var ctx context.Context = nil // if it's nil connection will form context from connection opts
451449
if len(optArgs) >= 1 {
452450
opts = optArgs[0].toMap()
453-
if optArgs[0].Context != nil {
454-
ctx = optArgs[0].Context
455-
}
451+
ctx = optArgs[0].Context
456452
}
457453

458454
if s == nil || !s.IsConnected() {

query_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
p "gopkg.in/gorethink/gorethink.v3/ql2"
55
)
66

7-
func formStopQuery(token int64) Query {
7+
func newStopQuery(token int64) Query {
88
return Query{
99
Type: p.Query_STOP,
1010
Token: token,

0 commit comments

Comments
 (0)