On first impression, coroutines appear more powerful than simple async/await, but also much more daunting
What I’m trying to achieve is a simple server-side model as in JS and Hack:
- each request is served by a single thread (no multi-threading per request)
- does not block on I/O
What I think I have figured out so far:
- Each time I use
async, I should pass
coroutineContextto avoid using thread pool
- The JS and Hack behavior seems to match
CoroutineStart.LAZY, so I have to pass
startas well (I am not sure of the implications of the default behavior where coroutines are started eagerly)
- I should probably have my async helper which automatically passes those parameters
- Is there a utility to wait for a list of
Deferreds in parallel? Something like
- If every method in codebase is marked as suspend, will there be a performance penalty, since this is not language level concept in Kotlin?
Am I generally looking in the right direction?