fix statuses generator regression

This commit is contained in:
wryk 2020-01-12 22:52:40 +01:00
parent ae187a96ef
commit 2c78fb6d3b
1 changed files with 12 additions and 5 deletions

View File

@ -51,18 +51,24 @@ export async function* mkStatusesIterator(initialLink) {
if (latestPreviousFetch + 5 * minute < now) {
console.log('fetch newer')
const previous = await fetchTimeline(previousLink)
console.log(`${previous.length} newers`)
latestPreviousFetch = now
if (previous.statuses.length) {
buffer.unshift(...previous.statuses)
previousLink = previous.links.prev
latestPreviousFetch = now
}
}
if (buffer.length === 0) {
console.log('fetch older')
const next = await fetchTimeline(nextLink)
if (next.statuses.length) {
buffer.push(...next.statuses)
nextLink = next.links.next
}
}
yield buffer.shift()
}
@ -96,6 +102,7 @@ export async function* mkTracksIterator(domain, hashtags) {
}
export async function fetchTimeline(url) {
console.log(`fetching ${url}`)
const response = await fetch(url)
const statuses = await response.json()