Previous episode: 09. Your Second Asynchronous App
Next episode: 11. Using Asynchronous Methods in Views
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Refresh your browser to check that the core server is running or restart the server in terminal. Continue with your project from the previous episode or open the starter project for this episode. Build and run the project. To complete the challenge in the previous episode, you downloaded and displayed this list of files. When you store files on a cloud server, you usually want to know how much storage you've used and whether you have duplicate files. This cloud server has an endpoint to supply this information. In Super Storage Model, locate the status method. Replace the dummy return statement with the usual code. You fetch the data and you check the status code. The returned data is just a string encoded with Unicode UTF8. Now go to list view and call this method inside the due closure after the call to available files. This course is about concurrency and your brain might now be telling you something's not quite right about what you just did. Hold that thought until you've checked this code works. Build and run. Below the list of files is a server usage message with random values for percentage and number of duplicate files. Okay, now back to that due closure. This first try await means the call to status doesn't start until the call to available files completes. Both calls are asynchronous and they call different server endpoints. They could run in the opposite order or they could run at the same time. How do you make this happen? Replace those two lines with these. Option click files to see it's now a local constant. But more, it's an async let constant. An async let constant is like a promise that a value or an error will become available. The async in async let means you must use a wait to access the promised value. Next, you need to group these two async calls. You use two pulls to group the two async let constants and the two results. If you have to await more than two or three results, you can use an array. Option click files result and status result to see their normal let constants. So now you can assign them to the views state properties to update the view. Add these lines at the end of the due closure. So you set the state properties of list view, build and run. Now the server requests to run at the same time so the UI becomes ready for the user a little faster. It's pretty amazing that the same async await and let syntax lets you run non-blocking asynchronous code serially and also concurrently. You're displaying server status in the list view. Next up, you'll start implementing the download view.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.