I am getting a but confused about how suspend work...
# coroutines
d
I am getting a but confused about how suspend works, if i call a none suspend function from a suspend function is it suspendable or do all the functions need to be marked as suspend?
z
a non suspend function can be called from a suspending or non-suspending context
d
I understand that What i am wondering is is there a performance difference from calling a suspend fn that calls non-suspending functions inside of it vs it having suspending functions. from what i understand there is not, but a colleague of mine with c# background disagrees.
z
I believe a suspend function that makes zero suspend calls will not have a state machine class generated for it. If it makes at least one suspending call, the state machine will be generated. But the state machine code is pretty efficient, unlikely to have any significant performance impact in most cases.
e
As a matter of style you don’t have to mark all your functions as
suspend
You only mark those functions as
suspend
that perform some long-running things and wait for them (like sending requests to server, etc). This way, your code and architecture because easier to read and to understand as there is a clear separation between fast local and potentially very slow remote computations.
K 8
❤️ 7
👍🏼 12