Improving efficiency using async-let
Even though your app is now responsive to button taps and can update the user interface while the makeToast()
and boilEggs()
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, as shown here:
async let temporaryConstant1 = methodName1()
async let temporaryConstant2 = methodName2()
await variable1 = temporaryConstant1
await variable2 = temporaryConstant1
In this example, methodName1()
and methodName2()
will run in parallel.
You will modify your app to use async-let
to enable the makeToast()
and poachEgg()
methods to run in parallel. In the ViewController
file, modify the code in the Task
block as follows:
Task {
let startTime = Date().timeIntervalSince1970...