In a legacy Objective-C application, I routinely use a one-to-many pattern for notifying delegates of a change. There is a single "Service" class and multiple "Client" classes. The client classes register for delegate notifications from different threads. The service makes no guarantees what thread the delegate notifications will be called on. The service has an internal array of references to the clients. Mutation of this array is protected by a lock in the service as clients can register and unregister from any thread.
In Combine, what thread safety rules do I have to follow when it comes to subscribing to a Publisher? If the service above exports a property of type AnyPublisher (perhaps an internal PassthroughSubject) does Combine allow clients to subscribe (and cancel) to that Publisher from any thread?
If not, then what is an effective pattern to use such that clients can chain operators to the exposed Publisher?
I noticed that this post was marked as off-topic. That's fine, but can someone please elaborate as to why? There was an existing
Combine tag and the
Using Swift category is described as:
This area is intended for users to get help with or ask questions about Swift or its related tools. Beginner questions welcome!