Exercise 1: A Real timer(every:count:) AsyncStream — Possible Solution ============================================================================= func timer(every interval: Duration, count: Int) -> AsyncStream { AsyncStream { continuation in Task { for value in 1...count { continuation.yield(value) try? await Task.sleep(for: interval) } continuation.finish() } } } // Consuming it: for await tick in timer(every: .seconds(1), count: 5) { print("Tick \(tick)") } // Prints: Tick 1, Tick 2, Tick 3, Tick 4, Tick 5 - one per real second HOW IT WORKS: timer(every:count:) follows the chapter's own countdown(from:) pattern exactly - AsyncStream's own real initializer takes a closure receiving a continuation, and a real Task is launched inside it to actually produce values over real time without blocking whoever eventually calls this function. Inside that Task, a real for value in 1...count loop calls continuation.yield(value) once per iteration - each yield delivers exactly one real value to whichever for await loop is currently consuming the stream - followed by try? await Task.sleep(for: interval), which genuinely pauses this specific task (not any other real work in the app) for the caller-specified real duration before producing the next value. Once the loop finishes all count iterations, continuation.finish() is called, correctly signalling the end of the real stream so the consuming for await loop exits cleanly on its own rather than waiting forever. The consuming for await loop reads each real yielded value in order, printing it as it arrives - genuinely receiving one new value roughly once per real second, rather than all five values arriving at once. ANSWER: timer(every:count:) correctly builds an AsyncStream that yields values 1 through count, pausing for the given real interval between each one via Task.sleep, and finishes cleanly afterward - a real for await loop consuming it receives each tick roughly once per interval, exactly matching the chapter's own countdown(from:) pattern applied to a new, parameterized case. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly implements a real, parameterized AsyncStream following the chapter's own established continuation/yield/finish pattern, with a real consuming loop demonstrating the timed delivery.