Skip to content

Commit

Permalink
Produce{,Sync}: default to context.Background if no ctx is provided
Browse files Browse the repository at this point in the history
... although it's against context docs, sometimes it's nice to just pass
nil and save typing so much.
  • Loading branch information
twmb committed Jan 6, 2022
1 parent eb2cec3 commit 029e655
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/kgo/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (f *FirstErrPromise) Err() error {
// The context is used if the client currently has the max amount of buffered
// records. If so, the client waits for some records to complete or for the
// context or client to quit. If the context / client quits, the promise is
// called with ctx.Err().
// called with ctx.Err(). If the context is nil, this defaults to context.Background().
//
// The context is also used on a per-partition basis to abort buffered records.
// If the context is done for the first record buffered in a partition, and if
Expand Down Expand Up @@ -283,6 +283,9 @@ func (cl *Client) Produce(
r *Record,
promise func(*Record, error),
) {
if ctx == nil {
ctx = context.Background()
}
if promise == nil {
promise = noPromise
}
Expand Down

0 comments on commit 029e655

Please sign in to comment.