Post

Replies

Boosts

Views

Activity

Reply to AsyncPublisher of KeyValueObservingPublisher doesn't work
This appears to be a bug in NSObject.KeyValueObservingPublisher. It's triggered because the values property only sends an initial Demand of .max(1) when it subscribes to the KVO publisher. Forcing a larger Demand works around the problem. We can use the handleEvents operator to send unlimited demand to the KVO publisher: Task { for await value in obj .publisher(for: \.count) .handleEvents(receiveSubscription: { $0.request(.unlimited) }) .values { print("async: \(value)") } }
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’24
Reply to AsyncPublisher of KeyValueObservingPublisher doesn't work
This appears to be a bug in NSObject.KeyValueObservingPublisher. It's triggered because the values property only sends an initial Demand of .max(1) when it subscribes to the KVO publisher. Forcing a larger Demand works around the problem. We can use the handleEvents operator to send unlimited demand to the KVO publisher: Task { for await value in obj .publisher(for: \.count) .handleEvents(receiveSubscription: { $0.request(.unlimited) }) .values { print("async: \(value)") } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Feb ’24