Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flatMapFirst #7

Closed
wants to merge 1 commit into from
Closed

fix flatMapFirst #7

wants to merge 1 commit into from

Conversation

hmhv
Copy link

@hmhv hmhv commented Jun 27, 2019

No description provided.

@freak4pc
Copy link
Member

Hey @hmhv - that looks great, thanks for the catch.

I was only wondering - flatMapFirst says:

If element is received while there is some projected observable sequence being merged it will simply be ignored.

Did you confirm maxPublishers: 1 has the same behavior where it drops streams during the processing of a previous one?

@hmhv
Copy link
Author

hmhv commented Jun 27, 2019

What about this?

maxPublishers
The maximum number of publishers produced by this method.

https://developer.apple.com/documentation/combine/publisher/3204712-flatmap

@freak4pc
Copy link
Member

That piece of docs isn't clear enough to be sure, so I tested this.
There is one key difference between RxSwift and Combine in this sense - and that's backpressure.

Here's the RxSwift example:

image

Note that every 3 seconds - the specific element emitted from the upstream is processing and others are "dropped" (like said in the docs)

Here's the Combine example:

image

Note that the upstream doesn't "drop items" at all - but never actually produces them since backpressure prevents the upstream from producing more elements. In this sense it's more like a concat since the flatMap is forced to complete before the upstream can product more elements.

I'm OK with listing it as a parallel even though ... in essence it's not too similar in behavior. What do you think ?

@freak4pc
Copy link
Member

Messing with this a bit more - I wouldn't say this is like flatMapFirst.

I just realized Observable.merge(maxConcurrent: 1) is really the parallel of flatMap(maxPublishers: .max(1)).

@hmhv
Copy link
Author

hmhv commented Jun 28, 2019

Thank you for your example. you are right.
flatMap(maxPublishers: .max(1)) is not ignored element

@hmhv hmhv closed this Jun 28, 2019
@freak4pc
Copy link
Member

This is still a very good point though, so I've added it in 416ec07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants