Avatar
@swift-5.5.3 actor State { var value = 0 func inc() -> Int { defer { value += 1 } return value } } Task { let state = State() let stream = AsyncStream<Int> { let v = await state.inc() print("produce", v) return v } onCancel: { @Sendable in print("cancel") } var count = 0 for await aa in stream { count += 1 if count > 10 { break } print("for", aa) await Task.sleep(1 * 1000 * 1000 * 1000) } }