Skip to content

Commit

Permalink
Add instructions on using NewClient in its Godoc docblock (#6)
Browse files Browse the repository at this point in the history
There's an example at the top of the River package demonstrating the use
of `NewClient`, but as I was reading the docs today, I realized that
since `NewClient` is somewhat non-trivial to invoke because it requires
a generic parameter, it'd be a good idea to also have an example of its
use right in `NewClient`'s docblock. That way, if a user is viewing this
function they don't need to go hunt around for examples to try and
figure out how to use it.
  • Loading branch information
brandur authored Nov 11, 2023
1 parent fa68ce5 commit 0776d75
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,30 @@ var (
// NewClient creates a new Client with the given database driver and
// configuration.
//
// Currently only one driver is supported, which is Pgx V5. See package
// Currently only one driver is supported, which is Pgx v5. See package
// riverpgxv5.
//
// The function takes a generic parameter TTx representing a transaction type,
// but it can be omitted because it'll generally always be inferred from the
// driver. For example:
//
// import "github.com/riverqueue/river"
// import "github.com/riverqueue/river/riverdriver/riverpgxv5"
//
// ...
//
// dbPool, err := pgxpool.New(ctx, os.Getenv("DATABASE_URL"))
// if err != nil {
// // handle error
// }
// defer dbPool.Close()
//
// riverClient, err := river.NewClient(riverpgxv5.New(dbPool), &river.Config{
// ...
// })
// if err != nil {
// // handle error
// }
func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client[TTx], error) {
if driver == nil {
return nil, errMissingDriver
Expand Down

0 comments on commit 0776d75

Please sign in to comment.