Forked from cartant/medium-rxjs-subsequent-composed.ts
Created
March 14, 2019 22:12
-
-
Save uzbekdev1/6d9160e9152560424ddbf5ddd00e4549 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function subsequent<T>( | |
count: number, | |
operator: (source: Observable<T>) => Observable<T> | |
): (source: Observable<T>) => Observable<T> { | |
return (source: Observable<T>) => new Observable<T>(observer => { | |
const published = source.pipe(publish()) as ConnectableObservable<T>; | |
const concatenated = concat( | |
published.pipe(take(count)), | |
published.pipe(operator) | |
); | |
const subscription = concatenated.subscribe(observer); | |
subscription.add(published.connect()); | |
return subscription; | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment