https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Ahmed

04/08/2022, 3:16 PM
Hey guys, do we need to await for the result returned by a suspended function ?
Copy code
runblock {
val result =  methodCall(). // this method is suspended 

repository.persistResultToDB(result)
}
so, the
methodCall()
do we need to await for its completion, to be able to use the returned
result
to persist them to the db ?
h

henrikhorbovyi

04/08/2022, 3:25 PM
if the
persistResultToDB()
method is also suspend so it will naturally waits for the result value. Because they are in the same coroutine scope
j

Joffrey

04/08/2022, 3:38 PM
No matter what
persistResultToDB
is, you don't need to await a suspend function when you call it, it returns the value directly and you can use it
a

Ahmed

04/08/2022, 4:04 PM
the
persistResultToDB
is not suspended !
j

Joffrey

04/08/2022, 4:06 PM
@Ahmed it doesn't matter, calling
methodCall()
directly and using the return value is correct
1
a

Ahmed

04/08/2022, 4:06 PM
Perfect! Thanks a lot
2 Views