From 9fa3d003d2b0d1f74f448966e211684aee2a5789 Mon Sep 17 00:00:00 2001 From: Davide Pianca <davidepianca98@gmail.com> Date: Wed, 11 Dec 2024 13:51:56 +0100 Subject: [PATCH] Add exception handler parameter to MQTTClient.runSuspend --- .../kotlin/io/github/davidepianca98/MQTTClient.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kmqtt-client/src/commonMain/kotlin/io/github/davidepianca98/MQTTClient.kt b/kmqtt-client/src/commonMain/kotlin/io/github/davidepianca98/MQTTClient.kt index 6ec25e4..5492e3b 100644 --- a/kmqtt-client/src/commonMain/kotlin/io/github/davidepianca98/MQTTClient.kt +++ b/kmqtt-client/src/commonMain/kotlin/io/github/davidepianca98/MQTTClient.kt @@ -60,6 +60,7 @@ import io.github.davidepianca98.socket.SocketClosedException import io.github.davidepianca98.socket.SocketInterface import io.github.davidepianca98.socket.streams.EOFException import io.github.davidepianca98.socket.tls.TLSClientSettings +import kotlinx.coroutines.CoroutineExceptionHandler /** * MQTT 3.1.1 and 5 client @@ -480,9 +481,13 @@ public class MQTTClient( * Run the client * This function runs the thread on the specified dispatcher until the client stops * @param dispatcher the dispatcher on which to run the client + * @param exceptionHandler the exception handler for the coroutine scope */ - public fun runSuspend(dispatcher: CoroutineDispatcher = Dispatchers.Default) { - CoroutineScope(dispatcher).launch { + public fun runSuspend( + dispatcher: CoroutineDispatcher = Dispatchers.Default, + exceptionHandler: CoroutineExceptionHandler = CoroutineExceptionHandler { _, throwable ->} + ) { + CoroutineScope(dispatcher).launch(exceptionHandler) { run() } } -- GitLab