I have a program, a web server, that currently use...
# coroutines
b
I have a program, a web server, that currently uses a cached thread pool executor with a default thread factory. Is there an easy way I can switch in coroutines there? I tried with project loom and it worked beautifully, is it similar in coroutines?
s
What do you mean by ‘switch’ in coroutines?
Switch threads?
b
I mean replace my code that uses threads with using coroutines instead
s
Ah… switch to coroutines 😄 I think you’d be interested in taking a look a Ktor.
b
Appreciate that but I’m kind of looking for specific advice on this, rather than advice on using something already made
c
a good starting point could be
Copy code
threadPool.asCoroutineDispatcher()
👍 1
z
I think the migration process will look significantly different than with loom. Coroutines are much more explicit, you have to mark functions as suspending and call other suspending functions, there are separate types for Mutex and Semaphore that are coroutine-compatible, there’s a new set of primitives (eg Channel, select) that are designed to build patterns that take advantages of coroutine features, etc. You’d probably end up rewriting a lot more code than I think you would with loom.
👍 3