Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver: Don't waste resources setting/being-notified up in progress handler if context cannot be canceled #13

Merged
merged 1 commit into from
Feb 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
if c.c.IsClosed() {
return nil, driver.ErrBadConn
}
c.c.ProgressHandler(progressHandler, 100, ctx)
defer c.c.ProgressHandler(nil, 0, nil)
if ctx.Done() != nil {
c.c.ProgressHandler(progressHandler, 100, ctx)
defer c.c.ProgressHandler(nil, 0, nil)
}
if len(args) == 0 {
if query == "unwrap" {
return nil, ConnError{c: c.c}
Expand Down Expand Up @@ -254,8 +256,10 @@ func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (drive
if err := s.s.bindNamedValue(args); err != nil {
return nil, err
}
s.s.c.ProgressHandler(progressHandler, 100, ctx)
defer s.s.c.ProgressHandler(nil, 0, nil)
if ctx.Done() != nil {
s.s.c.ProgressHandler(progressHandler, 100, ctx)
defer s.s.c.ProgressHandler(nil, 0, nil)
}
if err := s.s.exec(); err != nil {
return nil, ctxError(ctx, err)
}
Expand All @@ -270,7 +274,9 @@ func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driv
return nil, err
}
s.rowsRef = true
s.s.c.ProgressHandler(progressHandler, 100, ctx)
if ctx.Done() != nil {
s.s.c.ProgressHandler(progressHandler, 100, ctx)
}
return &rowsImpl{s, nil, ctx}, nil
}

Expand Down Expand Up @@ -308,7 +314,9 @@ func (r *rowsImpl) Next(dest []driver.Value) error {
}

func (r *rowsImpl) Close() error {
r.s.s.c.ProgressHandler(nil, 0, nil)
if r.ctx.Done() != nil {
r.s.s.c.ProgressHandler(nil, 0, nil)
}
r.s.rowsRef = false
if r.s.pendingClose {
return r.s.Close()
Expand Down