Why does this code snippet produces different results?
example(of: "async/await") {
let subject = CurrentValueSubject<Int, Never>(0)
Task {
for await element in subject.values {
print("Element: \(element)")
}
print("Completed.")
}
subject.send(1)
subject.send(2)
subject.send(3)
subject.send(completion: .finished)
}
Sample runs
Run 1:
——— Example of: async/await ———
Element: 1
Element: 2
Element: 3
Completed.
Run 2:
——— Example of: async/await ———
Element: 0
Element: 1
Element: 2
Element: 3
Completed.
Run 3:
——— Example of: async/await ———
Completed.
I sometimes get different results. Why?