Few clarification points: - By heavy I mean it can...
# coroutines
d
Few clarification points: - By heavy I mean it can block thread, e.g. long running operation - Yes, of course main point of
suspend
keyword is to mark suspension points, but it also serve as “marker” for caller: this function is compiled to function with continuation (callback) = this function has suspension point = this function may block your thread
l
Nope,
suspend
is not a "marker" for things that block threads.
suspend
is solely for allowing suspension points. If you want to have blocking code that can run on arbitrary thread pool, then coroutines are not your solution. "Regular" blocking code is yours, and a custom documented annotation, plus maybe ruling out UI/event loop thread(s) are your best solutions. A good one also is to name your function
getUserByIdBlocking(…)
, as suggested in official coroutines guide
👍 1