combine subscribeOn , what is the meaning of upstream?

https://developer.apple.com/documentation/combine/publishers says

"subscribe(on:) changes the execution context of upstream messages."


I did a little experiment.


Publishers.Just(1)

.map { _ in

print(Thread.isMainThread) // true

}

.subscribe(on: backgroundQueue)

.map { _ in

print(Thread.isMainThread) // false

}.sink {

print(Thread.isMainThread) // false



i expected false false false. but results was true false false

What does 'upstream' mean specifically?

Replies

Why did you expec t false for the first print ?

How do you know Publishers.Just(1) is not executing in the mainThread ?


If I understand correctly the doc:

https://developer.apple.com/documentation/combine/publisher/3204758-subscribe


upstream just means messages that comes from publishes to which receiver has subscribed. Receivers are downstream.

So, message coming from upstream will execute in the new specified context (queue).


Hope that helps.