From 2c78fb6d3b3f9164d9e8ff4f42462f89e712af23 Mon Sep 17 00:00:00 2001 From: wryk Date: Sun, 12 Jan 2020 22:52:40 +0100 Subject: [PATCH] fix statuses generator regression --- src/util.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/util.js b/src/util.js index 8bd52c3..e4874e2 100644 --- a/src/util.js +++ b/src/util.js @@ -51,17 +51,23 @@ export async function* mkStatusesIterator(initialLink) { if (latestPreviousFetch + 5 * minute < now) { console.log('fetch newer') const previous = await fetchTimeline(previousLink) - console.log(`${previous.length} newers`) - buffer.unshift(...previous.statuses) - previousLink = previous.links.prev + latestPreviousFetch = now + + if (previous.statuses.length) { + buffer.unshift(...previous.statuses) + previousLink = previous.links.prev + } } if (buffer.length === 0) { console.log('fetch older') const next = await fetchTimeline(nextLink) - buffer.push(...next.statuses) - nextLink = next.links.next + + 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()