-
Notifications
You must be signed in to change notification settings - Fork 97
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
#235 flatMapLatest adding overlapping option #236
Open
32bitkid
wants to merge
3
commits into
kefirjs:master
Choose a base branch
from
32bitkid:overlapping-flatMapLatest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import FlatMap from './flat-map'; | ||
|
||
export default function flatMapLatest(obs, fn, options) { | ||
if (typeof fn !== 'function') { | ||
options = fn; | ||
fn = undefined; | ||
} | ||
options = options === undefined ? {} : options; | ||
const { overlapping = false } = options; | ||
return new FlatMap(obs, fn, {concurLim: 1, drop: 'old', overlapping }).setName(obs, 'flatMapLatest'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this loop seemed a little weird when I was working on it, however, I think to have correct parity with the other side of the condition it needs to be here. Given that
this._curSources.length - this._concurLim > 1
, the other side, implicitly loops due to recursion. Since we want to add first, using_addToCur
, then we need to make sure that we aren't over the_concurLim
and blindly removing one might be not enough. Although, I'm not sure how anAbstractPool
could get into that state.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just remove one. Yes, there is a recursion on the other side, but it should always do only one iteration because:
this._curSources.length <= this._concurLim
.this._curSources.length === this._concurLim
should be true.this._curSources
, so nowthis._curSources.length === this._concurLim - 1
.this._add()
call, we fall into branch at line 33. And that is the end.But more importantly, with the condition you added we might actually remove none of the oldest. After
this._addToCur(toObs(obj))
we not necessarily have an observable added to_curSources
because iftoObs(obj)
already anded or ends immediately after we subscribe to it, we don't add it to the_curSources
(take a look at_addToCur
). Btw, we need a test case for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe it make sense to remove recursion on the other side too.
This way we get the correct parity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure thats quite equivalent; there may not be a public api to aggravate the condition, but I think that when
{ concurLim: 1, queueLim: 1, drop: 'old' }
, and given that both_curSources
and_queue
are full and I add another one, I would want to:_curSources
_queue
_queue
But, I'll need to think about it more. However, I think the same concern is valid for the overlapping side of the branch. If there is a queue, then one should add to
_queue
and let_removeOldest
pull it out of the queue, but that doesn't really resolve the actual use-case for using overlapping to begin with. I think I need to step back and think about it harder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right! I didn't realize that
_removeOldest
pulls from thequeue
. Replacingthis._add -> this._addToCur
isn't equivalent then indeed. I'll think about it too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't test it, but maybe we could do something like this?