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

Return values from both data and error channels at once #1

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 2 additions & 7 deletions cgo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,9 @@ func (conn *connection) execContext(ctx context.Context, query string) (*csComma
select {
case <-ctx.Done():
return nil, ctx.Err()
case cmd := <-recvCmd:
if cmd != nil {
return cmd, nil
}
case err := <-recvErr:
if err != nil {
return nil, err
}
cmd := <-recvCmd
return cmd, err
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions cgo/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewConnector(dsn libdsn.DsnInfo) (driver.Connector, error) {
driverCtx.drop()
return nil, fmt.Errorf("Failed to open connection: %v", err)
}

defer func() {
// In- and decrease connections count before and after closing
// connection to prevent the context being deallocated.
Expand Down Expand Up @@ -64,10 +65,9 @@ func (connector *connector) Connect(ctx context.Context) (driver.Conn, error) {
}
}()
return nil, ctx.Err()
case conn := <-connChan:
return conn, nil
case err := <-errChan:
return nil, err
conn := <-connChan
return conn, err
}
}

Expand Down
27 changes: 6 additions & 21 deletions cgo/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,9 @@ func (conn *connection) PrepareContext(ctx context.Context, query string) (drive
}
}()
return nil, ctx.Err()
case stmt := <-recvStmt:
if stmt != nil {
return stmt, nil
}
case err := <-recvErr:
if err != nil {
return nil, err
}
stmt := <-recvStmt
return stmt, err
}
}
}
Expand Down Expand Up @@ -291,14 +286,9 @@ func (stmt *statement) ExecContext(ctx context.Context, args []driver.NamedValue
select {
case <-ctx.Done():
return nil, ctx.Err()
case res := <-recvResult:
if res != nil {
return res, nil
}
case err := <-recvErr:
if err != nil {
return nil, err
}
res := <-recvResult
return res, err
}
}
}
Expand Down Expand Up @@ -343,14 +333,9 @@ func (stmt *statement) QueryContext(ctx context.Context, args []driver.NamedValu
}
}()
return nil, ctx.Err()
case rows := <-recvRows:
if rows != nil {
return rows, nil
}
case err := <-recvErr:
if err != nil {
return nil, err
}
rows := <-recvRows
return rows, err
}
}
}
9 changes: 2 additions & 7 deletions cgo/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,9 @@ func (conn *connection) BeginTx(ctx context.Context, opts driver.TxOptions) (dri
}
}()
return nil, ctx.Err()
case tx := <-recvTx:
if tx != nil {
return tx, nil
}
case err := <-recvErr:
if err != nil {
return nil, err
}
tx := <-recvTx
return tx, err
}
}
}
Expand Down