Last active
February 5, 2026 17:04
-
-
Save avii-7/7e85fd35572f52e1122915ed62332499 to your computer and use it in GitHub Desktop.
Deallocation Issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| final class StreamListner { | |
| private let stream: AsyncStream<Int> = AsyncStream<Int> { (continuation) in | |
| Task { | |
| for i in 1...20 { | |
| try? await Task.sleep(for: .seconds(2)) | |
| continuation.yield(i) | |
| } | |
| } | |
| } | |
| init() { | |
| Task { [weak self] in | |
| guard let self else { return } | |
| for await value in self.stream { | |
| self.notifyAPI(value) | |
| } | |
| } | |
| } | |
| private func notifyAPI(_ value: Int) { print("New Stream value: \(value)") } | |
| deinit { | |
| print("Deinit AsyncStreamTests") | |
| } | |
| } | |
| struct AsyncStreamView: View { | |
| var body: some View { | |
| Text("Hello, World!") | |
| .onAppear { | |
| let _ = StreamListner() | |
| } | |
| } | |
| } | |
| #Preview { | |
| AsyncStreamView() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment