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

Add concurrency parameter to switch and switchMap #347

Closed
benlesh opened this issue Sep 18, 2015 · 8 comments
Closed

Add concurrency parameter to switch and switchMap #347

benlesh opened this issue Sep 18, 2015 · 8 comments
Labels
feature PRs and issues for features help wanted Issues we wouldn't mind assistance with.
Milestone

Comments

@benlesh
Copy link
Member

benlesh commented Sep 18, 2015

Carried over from #215.

The idea is that you could then switch between more than one of the most recently emitted observables.

I think the usefulness of this in comparison to potential performance degradation is dubious, but it's worth trying and comparing numbers, since it should be a non-breaking change.

@benlesh benlesh added the help wanted Issues we wouldn't mind assistance with. label Sep 18, 2015
@staltz
Copy link
Member

staltz commented Sep 30, 2015

Is this issue done?

@benlesh
Copy link
Member Author

benlesh commented Sep 30, 2015

I don't believe so.

@trxcllnt
Copy link
Member

trxcllnt commented Oct 6, 2015

@Blesh isn't this just the difference between popping off the end of the pending queue instead of shifting? Though since this is switchMap we're talking about, we can implement this as a ring buffer instead of an unbounded Array.

@benlesh benlesh added this to the 5.0.0 release milestone Jan 15, 2016
@benlesh benlesh added feature PRs and issues for features priority: low labels Jan 15, 2016
@benlesh
Copy link
Member Author

benlesh commented Jun 17, 2016

Closing this issue as stale.

@benlesh benlesh closed this as completed Jun 17, 2016
@d3lm
Copy link

d3lm commented Oct 17, 2017

I'd like to bump this issue as I think that there are use cases where a concurrency parameter is very useful for switchMap. We already have such parameter for mergeMap and it would be great to have the same for switchMap. I have implemented switchMapWithConcurrency as a lettable operator. Maybe this can help.

function switchMapWithConcurrency<T>(project: (value) => Observable<T>, concurrent = 1) {
  const subscriptions: Array<Subscription> = [];

  return (source: Observable<any>): Observable<T> => {
    return Observable.create((observer: Observer<T>) => {
      const subscription = source.subscribe((sourceValue) => {
        if (subscriptions.length >= concurrent) {
          let lastSubscription = subscriptions.shift();
          lastSubscription.unsubscribe();
        }

        let innerSubscription = project(sourceValue).subscribe(innerValue => observer.next(innerValue));
        subscription.add(innerSubscription);
        subscriptions.push(innerSubscription);
      });

      return subscription;
    });
  }
}

This can either be used with .let or within .pipe. Here's a working demo on JSBin.

@benlesh benlesh reopened this Oct 17, 2017
@benlesh
Copy link
Member Author

benlesh commented Oct 17, 2017

Yeah... I think this feature has merit... it's just that:

  1. It's a low priority
  2. switchMap is a very hot-path operator, so whatever we do would have to have minimal impact on both the perf and the size of the operator.

@BioPhoton
Copy link
Contributor

Hi @benlesh

  1. switchMap is a very hot-path operator, so whatever we do would have to have minimal impact on both the perf and the size of the operator.

As 2 got even more important (usage of RxJS exploded) and the last activity on this issue was more than 2 years ago I believe it could be closed.

Please let me know your opinion.

@benlesh
Copy link
Member Author

benlesh commented Oct 3, 2019

Yeah. It's gone stale again. It's apparently not a feature people are hot to get.

@benlesh benlesh closed this as completed Oct 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature PRs and issues for features help wanted Issues we wouldn't mind assistance with.
Projects
None yet
Development

No branches or pull requests

5 participants