Skip to content

Commit

Permalink
Provide collected posts as part of the sources fetch progress
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Dec 19, 2024
1 parent 2d593a3 commit 263aef3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export type Progress = {
started: number
finished: number
errors: Error[]
posts: Post[]
}

export async function fetchPosts(cfg: Config, onProgress: (progress: Progress) => void): Promise<Post[]> {

type Task = () => Promise<MastodonStatus[]>;
let progress: Progress = {total: 0, started: 0, finished: 0, errors: []}
let progress: Progress = {total: 0, started: 0, finished: 0, errors: [], posts: []}

// Group tasks by domain (see below)
const domainTasks: Record<string, Array<Task>> = {}
Expand Down Expand Up @@ -81,8 +82,8 @@ export async function fetchPosts(cfg: Config, onProgress: (progress: Progress) =
}

// Collect results
const posts: Post[] = []
const addOrReplacePost = (post: Post) => {
const posts = progress.posts;
const i = posts.findIndex(p => p.id === post.id)
if (i >= 0)
posts[i] = post
Expand Down Expand Up @@ -126,7 +127,7 @@ export async function fetchPosts(cfg: Config, onProgress: (progress: Progress) =
await Promise.allSettled(groupedTasks.map(task => task()))

// Done. Return collected posts
return posts
return progress.posts
}

/**
Expand Down

0 comments on commit 263aef3

Please sign in to comment.