Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active May 13, 2018 07:11
Show Gist options
  • Select an option

  • Save cartant/1d3ae38bf08e3b2f88a027f2a3329fbd to your computer and use it in GitHub Desktop.

Select an option

Save cartant/1d3ae38bf08e3b2f88a027f2a3329fbd to your computer and use it in GitHub Desktop.
import { EMPTY, Observable, Subscription } from "rxjs";
import { concatMap, expand, map } from "rxjs/operators";
import { NotificationQueue } from "rxjs-etc";
import { get } from "./github";
function pages<T>(
uri: string,
notifier: Observable<any>
): Observable<T[]> {
return new Observable<any>(observer => {
const notificationQueue = new NotificationQueue(notifier);
const subscription = new Subscription();
subscription.add(notificationQueue.connect());
subscription.add(
get<T[]>(uri).pipe(
expand(({ next }) => {
if (next) {
return notificationQueue.pipe(
concatMap(() => get(next))
);
}
return EMPTY;
}),
map(({ content }) => content)
).subscribe(observer)
);
return subscription;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment