https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Patrick Ramsey

03/03/2021, 3:04 AM
Does kotlin have an equivalent of twisted’s
deferToThread()
? IE, a neat, packaged way to spawn a thread/run some blocking work on a thread pool, and monitor it from a coroutine which resumes the caller when the blocking code finishes?
Actually, think I answered my own question. Sorry, still an early learner!
But I think the answer is
Copy code
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
    someBlockingOperation()
}
(right? 😄 )
r

rnett

03/03/2021, 3:16 AM
Possibly
async
if you want to start a new coroutine, but it's Dispatchers.IO, yeah.
p

Patrick Ramsey

03/03/2021, 4:28 AM
thanks!
5 Views