Without Swift Concurrency, you'd write something like this (pseudocode):
GetWeather() { results in
// Do something with the results
UpdateUI(results)
}
The part in the curly braces is a closure/completion handler. The GetWeather call is not blocking, so it runs on another thread and then it calls your completion code when it's done.
This looks fine in a small example, but it quickly gets gnarly when you need to pipe those results to something else, or you can also end up deep in many completion handlers.
With the new concurrency model it's just this
let results = await GetWeather ()
UpdateUI(results)
Now let's say your UpdateUI call was also non blocking:
They're saying that since it supports async/await the developer doesn't need to deal with callbacks/whatever. That line is accurate ("just a few lines of code") but also marketing.
GetWeather() { results in
}The part in the curly braces is a closure/completion handler. The GetWeather call is not blocking, so it runs on another thread and then it calls your completion code when it's done.
This looks fine in a small example, but it quickly gets gnarly when you need to pipe those results to something else, or you can also end up deep in many completion handlers.
With the new concurrency model it's just this
let results = await GetWeather ()
UpdateUI(results)
Now let's say your UpdateUI call was also non blocking:
GetWeather() { results in
}Which just becomes this
let results = await GetWeather ()
await UpdateUI(results)
DoSomethingElse()