Hi, I'm trying to use async/await
for KVO and it seems something is broken.
For some reason, it doesn't go inside for in
body when I'm changing the observed property.
import Foundation
import PlaygroundSupport
class TestObj: NSObject {
@objc dynamic var count = 0
}
let obj = TestObj()
Task {
for await value in obj.publisher(for: \.count).values {
print(value)
}
}
Task.detached {
try? await Task.sleep(for: .microseconds(100))
obj.count += 1
}
Task.detached {
try? await Task.sleep(for: .microseconds(200))
obj.count += 1
}
PlaygroundPage.current.needsIndefiniteExecution = true
Expected result: 0, 1, 2
Actual result: 0
Does anyone know what is wrong here?