From 029e65549d78531915df452289707baf130c7c9e Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Wed, 5 Jan 2022 18:19:49 -0700 Subject: [PATCH] Produce{,Sync}: default to context.Background if no ctx is provided ... although it's against context docs, sometimes it's nice to just pass nil and save typing so much. --- pkg/kgo/producer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/kgo/producer.go b/pkg/kgo/producer.go index 42a47956..36632b0c 100644 --- a/pkg/kgo/producer.go +++ b/pkg/kgo/producer.go @@ -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 @@ -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 }