Suspend Function In Kotlin-Coroutines
24 July, 2021
2
2
0
Contributors
Make Sure
That You Have Included Coroutines Dependency If It's Not Included:Can Be Paused
And Resumed Later In Your Code
.Suspend Function Can Execute Long-Running Operations || Tasks And Will Wait For It To Complete Without Blocking The Whole Code.
Speciality
Of Suspend Function Is That It Can Be Only Implemented In Another Suspend Function || Coroutine
.delay()
Is Also A Suspend Function That delays the coroutine for a specific time.delay()
In Your Code, Your IDE May Show This Image
In The Numerical Panel Where You Have Implemented A Suspend Function
👇🏼This Image Simply Means That You Are Implementing A Suspend Function.
delay()
Is Also A Suspend Sunction
Which Means That You Should Implement delay()
In A Suspend Function
Or In A Coroutine
Outside Of A Supend Function Or A Coroutine
Leads To This Beautiful Error🤭
:suspend
Before You Create The Function:delaying()
Function:Suspend Function Can Be Called || Implemented In Suspend Function Or In A Coroutine
.GlobalScope.launch{ }
In Your Main Thread:Note:
You Should NOT
Use GlobalScope every time.delaying()
In Coroutine:delaying()
Outside, Of A Coroutine You'll Get This Error As delaying()
Is A Suspend Function:Log
To Check If The delaying()
Is Working Or Not:Bye🤗
android
android studio
coroutines
kotlin
suspend