From 577ebc4c8411fac716a0333a49dd61900afd44df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 16 Aug 2023 17:49:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E7=9A=84=E6=97=B6=E5=80=99=E7=BB=93=E6=9E=9C=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- producer.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/producer.go b/producer.go index e8f2eea..795736b 100644 --- a/producer.go +++ b/producer.go @@ -115,17 +115,15 @@ func (p *Producer) Async(data ProducerData) ProducerResult { result := ProducerResult{} p.asyncProducer.Input() <- p.buildMessage(data) // 如果打开了Return.Successes配置,则等同于同步方式 + t := time.NewTicker(time.Second) select { case msg := <-p.asyncProducer.Successes(): result.Partition = msg.Partition result.Offset = msg.Offset case err := <-p.asyncProducer.Errors(): result.Err = err - default: - // 为什么要有default ? - // 则这段代码会挂住,因为设置没有要求返回成功config.Producer.Return.Successes = false, - // 那么在select等待的时候producer.Successes()不会返回,producer.Errors()也不会返回(假设没有错误发生),就挂在这儿。 - // 当然可以加一个default分支绕过去,就不会挂住了: + case <-t.C: + result.Err = errors.New("produce data wait result timeout") } return result }