Improving efficiency using async-let
Even though your app is now responsive to button taps and is able to update the user interface while the makeToast()
and poachEgg()
methods are running, both methods still execute sequentially. The solution here is to use async-let
. Writing async
in front of a let
statement when you define a constant, and then writing await
when you access the constant, allows parallel execution of asynchronous methods:
async let temporaryConstant1 = methodName1() async let temporaryConstant2 = methodName2() await variable1 = temporaryConstant1 await variable2 = temporaryConstant1
Here, methodName1()
and methodName2()
will run in parallel.
You will modify your app to use async-let
to enable the makeToast()
and poachEgg()
methods run in parallel. In the ViewController
file, modify the code in the Task
block as follows:
Task { let startTime = Date().timeIntervalSince1970 toastLabel.text = "Making toast..."...