``` val threadPool = newSingleThreadContext("git-c...
# coroutines
j
Copy code
val threadPool = newSingleThreadContext("git-clone-subprocess-pool")

suspend fun clone(urL: String) {
    val result = withContext(threadPool) {
        async {
            val pb = NuProcessBuilder(listOf("/bin/cat"))
            val process = pb.start()
            process.waitFor(0, TimeUnit.SECONDS)
        }
    }
    
    val exitcode = result.await()
}
a
If you have stuff between
async
and
await
then it's good. Otherwise just use
withContext
You should also be able to add context directly in
async
, though as you can see in the post above there are sometimes issues
j
Copy code
suspend fun clone(urL: String) {
    val exitcode = withContext(threadPool) {
        val pb = NuProcessBuilder(listOf("/bin/cat"))
        val process = pb.start()
        process.waitFor(0, TimeUnit.SECONDS)
    }
}
gotcha
a
Yeah. and assuming you want to return the exit code, add the return type to your clone function. Or just do
clone(url: String) = withContext(threadPool) ...
l
You can also use
<http://Dispatchers.IO|Dispatchers.IO>
for this kind of usage