kpavlov / jreactive-8583

Kotlin/Java Client & Server for ISO8583 & Netty
Apache License 2.0
317 stars 141 forks source link

Coroutine support for client.send #157

Open VovkaSOL opened 8 months ago

VovkaSOL commented 8 months ago

Hi, now client.send return future, but if we use Kotlin in client app, we can use coroutine for non blocking. Please add coroutine callback wrapper with suspendCoroutine.

VovkaSOL commented 6 months ago
    suspend fun suspendSendMsg(request: String): String {
        return suspendCoroutine { continuation ->
            try {
                sendMsg(request) { response ->
                    //continuation.resumeWith(Result.failure(InternalTimeoutException( "Таймаут ответа ${request!!::class.java.canonicalName} со временем ожидания ${finalTimeout.toMillis()} миллисекунд" ) ))
                    continuation.resumeWith(Result.success(response))
                }
            } catch (e: Exception) {
                LOGGER.error("что то сломалось при отправке iso сообщения", e)
                throw RuntimeException("что то сломалось при отправке iso сообщения")
            }
        }
    }