use Async
This hook function accepts a suspend function as a parameter and returns a function(use to execute suspend function). When you call the execution function, the suspend function will be executed within the coroutine scope of the current component.
// Declare an suspend lambda like a normal lambda
val async = useAsync {
delay(1.seconds)
setState(state + 1)
}
// easy to use
async()
Content copied to clipboard
Return
Receiver
Parameters
fn
This is a hook function that simplifies the use of coroutine scope. It's usage similar to the run function. Equivalent to scope.launch { }
val asyncRun = useAsync()
asyncRun {
// do something
}
Content copied to clipboard