You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
withLatestFrom doesn't seem to be thread safe when subscribing to two different publishers that emit elements from different threads.
This is part of the current implementation of withLatestFrom. Check the comments in uppercase.
privatefunc trackLatestFromSecond(onInitialValue:@escaping()->Void){vargotInitialValue= false
letsubscriber=AnySubscriber<Other.Output,Other.Failure>(
receiveSubscription:{[weak self] subscription inself?.otherSubscription = subscription
subscription.request(.unlimited)},
receiveValue:{[weak self] value in
guard let self =selfelse{return.none }// THIS IS CALLED FROM THREAD Bself.latestValue = value
if !gotInitialValue {// When getting initial value, start pulling values// from upstream in the main sinkself.sink =Sink(upstream:self.upstream,
downstream:self.downstream,
transformOutput:{[weak self] value in
guard let self =self,// THIS IS CALLED FROM THREAD A, ACCESSING THE SAME VAR BUT IT IS NOT SYNCHRONIZEDlet other =self.latestValue else{returnnil}returnself.resultSelector(value, other)},
transformFailure:{ $0 })// Signal initial value to start fulfilling downstream demand
gotInitialValue = true
onInitialValue()}return.unlimited
},
receiveCompletion:nil)self.second.subscribe(subscriber)}
Should a lock over latestValue be added to ensure thread safety? Are there reasons not to do it (for example, performance)? Should CombineExt at least update the Swift docs saying it is not supposed to be used from multiple threads?
Thank you.
The text was updated successfully, but these errors were encountered:
withLatestFrom doesn't seem to be thread safe when subscribing to two different publishers that emit elements from different threads.
This is part of the current implementation of withLatestFrom. Check the comments in uppercase.
Should a lock over latestValue be added to ensure thread safety? Are there reasons not to do it (for example, performance)? Should CombineExt at least update the Swift docs saying it is not supposed to be used from multiple threads?
Thank you.
The text was updated successfully, but these errors were encountered: