Previous episode: 04. Using AsyncStream for Notifications
Next episode: 06. Unit Testing
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.
Your challenge is to rewrite countdown to using the buffered, push-based version of AsyncStream. (upbeat music) Use Timer instead of Task.sleep to wait one second between messages. The starter project already has code for Timer.scheduledTimer that fires every second. Inside the scheduledTimer closure, yield the correct message when countdown is 3, 2, 1, and 0. Remember to decrement countdown after yielding 3, 2, and 1. When countdown is 0, return the user's message, invalidate the timer, and finish the continuation. Good luck. (casual music) Welcome back. Hopefully, you had success with this task. Here's how I did it. In BlabberModel, countdown to already has starter code to create a timer that fires each second. Instead of the pull-based AsyncStream code you wrote in Episode 3, inside the Timer closure, I first handled the countdown digits. On every timer tick, I called yield on the continuation to produce the countdown value and then decreased countdown. Next, I needed to add code for when countdown reaches 0. I did this before continuation.yield. When countdown reaches 0, I stopped the timer, yield the user's message, and call continuation.finish to complete the sequence. Actually, there's a shortcut to produce the last value and complete the sequence at the same time. And to show it works. The next episode is about unit testing.
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.