From 43c5bb0a3c3a2406c8ea04f5a11e8d7b22775d05 Mon Sep 17 00:00:00 2001 From: Cody Jones Date: Sun, 26 Sep 2021 14:34:42 -0700 Subject: [PATCH] Connection and Cursor can be used concurrently The "not thread safe" comments are seven years old and no longer apply. --- connection.go | 7 +++---- cursor.go | 6 ++---- pool.go | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/connection.go b/connection.go index 6532cba3..67bdaebf 100644 --- a/connection.go +++ b/connection.go @@ -1,21 +1,21 @@ package rethinkdb import ( + "bytes" "crypto/tls" "encoding/binary" "encoding/json" "fmt" "net" + "sync" "sync/atomic" "time" - "bytes" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/log" "golang.org/x/net/context" p "gopkg.in/rethinkdb/rethinkdb-go.v6/ql2" - "sync" ) const ( @@ -41,8 +41,7 @@ type Response struct { Profile interface{} `json:"p"` } -// Connection is a connection to a rethinkdb database. Connection is not thread -// safe and should only be accessed be a single goroutine +// Connection is a connection to a RethinkDB database. type Connection struct { net.Conn diff --git a/cursor.go b/cursor.go index 170ca833..422b64a3 100644 --- a/cursor.go +++ b/cursor.go @@ -43,10 +43,8 @@ func newCursor(ctx context.Context, conn *Connection, cursorType string, token i return cursor } -// Cursor is the result of a query. Its cursor starts before the first row -// of the result set. A Cursor is not thread safe and should only be accessed -// by a single goroutine at any given time. Use Next to advance through the -// rows: +// Cursor is the result of a query. It starts before the first row +// of the result set. Use Next to advance through the rows: // // cursor, err := query.Run(session) // ... diff --git a/pool.go b/pool.go index 3b13387b..4fd29a53 100644 --- a/pool.go +++ b/pool.go @@ -19,7 +19,7 @@ const ( type connFactory func(host string, opts *ConnectOpts) (*Connection, error) -// A Pool is used to store a pool of connections to a single RethinkDB server +// Pool evenly distributes queries across a set of connections to a RethinkDB server. type Pool struct { host Host opts *ConnectOpts