I know that we wait with await
and execute a task without need to wait with async let
, but I can't understand the difference between these two calls:
async let resultA = myAsyncFunc()
async let resultB = await myAsyncFunc()
In my experiment, both of these seem to behave exactly the same, and the await
keyword does not have any effects here, but I'm afraid I'm missing something.
Thanks in advance for explanation on this. 🙏🏻
Update
I'm adding a working sample so you can see the behavior
func myAsyncFuncA() async -> String {
print("A start")
try? await Task.sleep(for: .seconds(6))
return "A"
}
func myAsyncFuncB() async -> String {
print("B start")
try? await Task.sleep(for: .seconds(3))
return "B"
}
async let resultA = myAsyncFuncA()
async let resultB = await myAsyncFuncB()
print("Both have been triggered")
await print(resultA, resultB)
Results:
A start // Immediately
B start // Immediately
Both have been triggered // Immediately
A B // After 6 seconds
So as you can see, resultA
does not block the context and the total waiting time is the biggest waiting time.