i have a question about suspend functions and awai...
# getting-started
x
i have a question about suspend functions and await (thread)
lets say you have a function
Copy code
suspend fun returnVal(){
  anotherClass.checkSomething()
  return "hello"
}
check something looks like something like this:
Copy code
suspend fun checkSomething(){
  if (asyncFunction()){
    throw Exception()
  } else {
    return
  }
}
and lastly,
Copy code
suspend fun asyncFunction(){
   return anotherAsync.await() == false
}
since there is an await on asyncFunction, its not necessary to explicitly await the checkSomething() function to make sure it will throw when it needs to, before returning "hello", correct?
v
You cannot explicitly await
checkSomething()
as it is a
Unit
function.
await()
is a function on
Deferred
. And yes, as you
await
anotherAsync
,
asyncFunction
will not complete until it is finished and thus
checkSomething
will not complete earlier either.
x
as expected, awesome! thank you
i thought i might have to convert to deferred unit or something, haha!