Experimenting with Combine, I've seen this behavior but I can't explain why is happening. I'm not trying to achieve nothing in particular so the example doesn't make any sense, I'm just trying to understand why is this happening.
From the print statement in the sink I get :
If I add I send anther value to the cvsTwo, while I'm expecting just one value printed from sink I get the value sent repeated 4 times that is the count of the array elements.
Code Block let cvsOne = CurrentValueSubject<Int, Never>(0) let cvsTwo = CurrentValueSubject<Int, Never>(5) let canc = [0,1,2,3].publisher .flatMap { (_) in return cvsOne } .flatMap { (_) in return cvsTwo } .sink { (value) in print("Received \(value)") }
From the print statement in the sink I get :
And it's ok.Received 5
Received 5
Received 5
Received 5
If I add I send anther value to the cvsTwo, while I'm expecting just one value printed from sink I get the value sent repeated 4 times that is the count of the array elements.
Code Block cvsTwo.send(10)
I really do not understand why, attaching print to the publishers flow I see that the array publisher complete with a finish event, but it seems that right after I send the value is triggered again.Received 10
Received 10
Received 10
Received 10
Can someone explain that to me?receive subscription: ([0, 1, 2, 3])
request unlimited
receive value: (0)
Received 5
receive value: (1)
Received 5
receive value: (2)
Received 5
receive value: (3)
Received 5
receive finished
Received 10
Received 10
Received 10
Received 10