async function* asynchronouslyGenerateAllMyTracks() {
const pageSize = 50;
function get50Tracks(off, lim = pageSize) {
return api.getMySavedTracks({
limit: lim,
offset: off
});
}
const head = await get50Tracks(0);
yield* head.body.items;
const pages = Math.floor(head.body.total / pageSize);
const offsets = Array(pages)
.fill(0)
.map((e, i) => i + 1)
.map(x => x * pageSize);
const remainingGetTrackCalls = offsets.map(offset => get50Tracks(offset));
for await (const pageRequest of remainingGetTrackCalls) {
yield* pageRequest.body.items;
}
}