From 500d2990ed70d21f4b9258d6114758ffe705da3d Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Mon, 8 Apr 2024 11:21:20 -0400 Subject: [PATCH] Use complete instead of cancel --- .../io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt b/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt index 7cf441166..17aa5ecd7 100644 --- a/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt +++ b/library/runtime-ctrl/src/jsMain/kotlin/io/matthewnelson/kmp/tor/runtime/ctrl/TorCtrl.kt @@ -252,20 +252,20 @@ public actual interface TorCtrl : Destroyable, TorEvent.Processor, TorCmd.Privil val _chunk = chunk.asDynamic() for (i in command.indices) { _chunk[i] = command[i] } - val wLatch = Job() - var dLatch: Job? = null + val wLatch: CompletableJob = Job(currentCoroutineContext()[Job]) + var dLatch: CompletableJob? = null try { val immediate = socket.write(chunk, callback = { - wLatch.cancel() + wLatch.complete() // fill for (i in command.indices) { _chunk[i] = 0 } }) if (!immediate) { - dLatch = Job() - socket.once("drain") { dLatch.cancel() } + dLatch = Job(wLatch) + socket.once("drain") { dLatch.complete() } } } catch (t: Throwable) { wLatch.cancel()