diff --git a/shared/src/commonMain/kotlin/com/neodesktop/dmodem/fax/T30.kt b/shared/src/commonMain/kotlin/com/neodesktop/dmodem/fax/T30.kt index a561147..a2d2365 100644 --- a/shared/src/commonMain/kotlin/com/neodesktop/dmodem/fax/T30.kt +++ b/shared/src/commonMain/kotlin/com/neodesktop/dmodem/fax/T30.kt @@ -608,7 +608,7 @@ object T30 { if (e.post != MPS) break } when { - e.dcs != null -> { d = e.dcs!!; continue } + e.dcs != null -> { d = e.dcs; continue } e.dcn -> if (pages > 0) return p.copy(phase = "Received") else throw FaxException("the sender hung up") e.post == EOM -> continue@outer e.post == EOP -> { diff --git a/shared/src/commonMain/kotlin/com/neodesktop/dmodem/io/Threads.kt b/shared/src/commonMain/kotlin/com/neodesktop/dmodem/io/Threads.kt index 7a0de23..935b31c 100644 --- a/shared/src/commonMain/kotlin/com/neodesktop/dmodem/io/Threads.kt +++ b/shared/src/commonMain/kotlin/com/neodesktop/dmodem/io/Threads.kt @@ -11,9 +11,16 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +/** + * The threads for blocking work: as many as there is work (I/O's 64, the + * default, would leave the 65th blocking read waiting for one of the + * others to end, which may be never) + */ +private val blocking = Dispatchers.IO.limitedParallelism(4096) + /** [f] on a thread of its own for blocking work (the JVM's daemon threads: coroutines' I/O threads) */ @OptIn(DelicateCoroutinesApi::class) -fun background(@Suppress("UNUSED_PARAMETER") name: String, f: () -> Unit): Job = GlobalScope.launch(Dispatchers.IO) { f() } +fun background(@Suppress("UNUSED_PARAMETER") name: String, f: () -> Unit): Job = GlobalScope.launch(blocking) { f() } /** waited for until counted down, once (the JVM's CountDownLatch(1)) */ class Latch {