From 90a4480868d66f882f60709c892dd93fd765418a Mon Sep 17 00:00:00 2001 From: nivida Date: Mon, 28 Aug 2023 14:01:09 +0200 Subject: [PATCH] type declaration fixed --- internal/kafka/producer/synchronous_producer.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/kafka/producer/synchronous_producer.ts b/internal/kafka/producer/synchronous_producer.ts index 0c5e324..e2ea6bc 100644 --- a/internal/kafka/producer/synchronous_producer.ts +++ b/internal/kafka/producer/synchronous_producer.ts @@ -59,8 +59,8 @@ export class SynchronousProducer extends AbstractProducer { timestamp?: number ): Promise { return new Promise(async (resolve, reject) => { - let deliveryListener: (error: LibrdKafkaError, report: DeliveryReport) => void; - + let deliveryListener: undefined | ((error: LibrdKafkaError, report: DeliveryReport) => void); + try { const identifier = { time: Date.now() }; const timer = setTimeout(() => { @@ -89,7 +89,9 @@ export class SynchronousProducer extends AbstractProducer { return; } }; + this.on("delivery-report", deliveryListener); + await this.sendToInternalProducer( key, message, @@ -103,7 +105,9 @@ export class SynchronousProducer extends AbstractProducer { this.poll(); }, 100); } catch (error) { - this.removeListener("delivery-report", deliveryListener); + if (deliveryListener) { + this.removeListener("delivery-report", deliveryListener); + } throw KafkaError.createUnknown(error); }