jsTest.RunTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mqtt-4-models Show documentation
Show all versions of mqtt-4-models Show documentation
Defines the MQTT 3 and 4 control packets
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise
import kotlinx.coroutines.withTimeout
import kotlin.js.Promise
import kotlin.time.Duration.Companion.seconds
actual fun block(body: suspend CoroutineScope.() -> T): dynamic = runTestInternal(block = body)
fun runTestInternal(
block: suspend CoroutineScope.() -> T
): Promise {
val promise = GlobalScope.promise {
try {
return@promise withTimeout(10.seconds) {
block()
}
} catch (e: UnsupportedOperationException) {
println("\r\nunsupported operation, skipping")
e.printStackTrace()
} catch (e: Exception) {
e.printStackTrace()
}
return@promise null
}
promise.catch {
if (it !is UnsupportedOperationException) {
throw it
}
}
return promise
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy