Skip to content

Commit

Permalink
type declaration fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida committed Aug 28, 2023
1 parent 5c6d229 commit 90a4480
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/kafka/producer/synchronous_producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class SynchronousProducer extends AbstractProducer {
timestamp?: number
): Promise<DeliveryReport | KafkaError> {
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(() => {
Expand Down Expand Up @@ -89,7 +89,9 @@ export class SynchronousProducer extends AbstractProducer {
return;
}
};

this.on("delivery-report", deliveryListener);

await this.sendToInternalProducer(
key,
message,
Expand All @@ -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);
}
Expand Down

0 comments on commit 90a4480

Please sign in to comment.