Skip to content

Commit

Permalink
👍 Allow task generators to be async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
takker99 committed Jan 5, 2022
1 parent 00a6ed3 commit 3c06caf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plan.ts
Expand Up @@ -15,7 +15,7 @@ export type IsTaskPortalPage = (title: string) => boolean;
*
* @param date 実行日
*/
export type TaskGenerator = (date: Date) => Task[];
export type TaskGenerator = (date: Date) => Task[] | Promise<Task[]>;

export async function* makeDiaryPages(
dates: Iterable<Date>,
Expand All @@ -27,7 +27,10 @@ export async function* makeDiaryPages(
for await (
const generate of getFunctions(isTaskPortalPage, "generate.js")
) {
for (const task of generate(date)) {
const pending = generate(date);
for (
const task of pending instanceof Promise ? await pending : pending
) {
lines.push(toString(task));
}
}
Expand Down

0 comments on commit 3c06caf

Please sign in to comment.