@@ -37,6 +37,9 @@ KafkaConsumer::KafkaConsumer(Conf* gconfig, Conf* tconfig):
37
37
38
38
consume_callback = nullptr ;
39
39
40
+ uv_async_init (Nan::GetCurrentEventLoop (), &consume_async, ConsumeMessage);
41
+ consume_async.data = this ;
42
+
40
43
uv_mutex_init (&consume_messages_lock);
41
44
}
42
45
@@ -50,6 +53,8 @@ KafkaConsumer::~KafkaConsumer() {
50
53
}
51
54
52
55
uv_mutex_destroy (&consume_messages_lock);
56
+
57
+ uv_close ((uv_handle_t *) &consume_async, NULL );
53
58
}
54
59
55
60
Baton KafkaConsumer::Connect () {
@@ -497,7 +502,7 @@ void KafkaConsumer::ConsumeLoop(void *arg) {
497
502
RdKafka::ErrorCode ec = b.err ();
498
503
if (ec == RdKafka::ERR_NO_ERROR) {
499
504
RdKafka::Message *message = b.data <RdKafka::Message*>();
500
- switch (message->err ()) {
505
+ switch (message->err ()) {
501
506
502
507
case RdKafka::ERR_NO_ERROR: {
503
508
// message is deleted after it's passed to the main event loop
@@ -538,8 +543,6 @@ void KafkaConsumer::ConsumeLoop(void *arg) {
538
543
looping = false ;
539
544
}
540
545
}
541
-
542
- uv_close ((uv_handle_t *) &consumer->consume_async , NULL );
543
546
}
544
547
545
548
void KafkaConsumer::ConsumeMessage (uv_async_t * handle) {
@@ -676,9 +679,6 @@ void KafkaConsumer::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
676
679
v8::Local<v8::Object> context = v8::Local<v8::Object>::Cast (info[0 ]);
677
680
consumer->consume_context .Reset (context);
678
681
679
- uv_async_init (Nan::GetCurrentEventLoop (), &consumer->consume_async , ConsumeMessage);
680
- consumer->consume_async .data = consumer;
681
-
682
682
// Wrap it
683
683
consumer->Wrap (info.This ());
684
684
0 commit comments