Thread Safety for Combine Publishers

PassthroughSubject (and CurrentValueSubject) takes a lock around sending values downstream specifically to enforce the serialization rule (there is one lock per downstream). So subject.send(1) from any thread should be ok.

For the subscription part, PassthroughSubject will take a lock around its own internal data structure of a list of downstream subscriptions. So the second part should be ok too, when the Client.init is invoked on several threads.

2 Likes