Skip to content

Commit

Permalink
Remove completable future usage with null
Browse files Browse the repository at this point in the history
  • Loading branch information
HindujaB committed Nov 18, 2024
1 parent 0a5b618 commit 35a8b6d
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.stdlib.mqtt.utils.MqttConstants;
import io.ballerina.stdlib.mqtt.utils.MqttUtils;
import io.ballerina.stdlib.mqtt.utils.Util;
import org.eclipse.paho.mqttv5.client.MqttClient;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand All @@ -49,16 +47,14 @@ public static Object complete(Environment env, BObject callerObject) {
int messageId = (int) callerObject.getNativeData(MqttConstants.MESSAGE_ID);
int qos = (int) callerObject.getNativeData(MqttConstants.QOS);
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
executorService.execute(() -> {
try {
subscriber.messageArrivedComplete(messageId, qos);
future.complete(null);
} catch (MqttException e) {
future.complete(MqttUtils.createMqttError(e));
throw MqttUtils.createMqttError(e);
}
});
return Util.getResult(future);
return null;
});
}

Expand All @@ -74,16 +70,14 @@ public static Object respond(Environment env, BObject callerObject, BMap message
mqttMessage.getProperties().setCorrelationData(correlationData);
}
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
executorService.execute(() -> {
try {
subscriber.publish(responseTopic, mqttMessage);
future.complete(null);
} catch (MqttException e) {
future.complete(MqttUtils.createMqttError(e));
throw MqttUtils.createMqttError(e);
}
});
return Util.getResult(future);
return null;
});
}
}

0 comments on commit 35a8b6d

Please sign in to comment.