I just witnessed an unexpected behaviour from Zip publisher when combined with flatMap operator and I'm not sure if this is a bug or just incomplete knowledge on my part given that I used RxSwift up until now.
Here is the code :
let trigger = CurrentValueSubject<Void, Never>(())
C.cancellable = Just([String]())
.flatMap {
Publishers.Zip($0.publisher.print("publisher"), trigger).print("Zip")
}
.print("flatMap")
.sink(receiveCompletion: { _ in print("completed") },
receiveValue: { print($0) })
The cancellable is kept as a static variable so that it doesn't get cleaned up.
I expected to fall into the "receiveCompletion" closure and see the "completed" displayed in the console as Zip should finish once one of the sources finishes. Instead it seems the finished message seems to be lost in the flatmap. Here is the console content :
flatMap: receive subscription: (FlatMap)
flatMap: request unlimited
publisher: receive subscription: (Empty)
publisher: receive finished
Zip: receive finished
I also tried to put values in the String sequence :
Just(["lo", "la", "li"])
.flatMap ...
and the first value arrives but the finished doesn't make his way out of the flatMap.
Does somebody have an explanation for this ? What can I do to avoid this ?
Thanks in advance !