Skip to content

Commit baccd69

Browse files
committed
feat: support async solve functions
1 parent fa1440d commit baccd69

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

bin/aoc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async function solve(
135135
console.log(gray(`running solve from ${moduleName}`));
136136
try {
137137
const start = performance.now();
138-
const answer = solve(input);
138+
const answer = await solve(input);
139139
const end = performance.now();
140140
const duration = end - start;
141141
console.log(

lib/harness.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import DotLetters from "@lib/DotLetters.ts";
33
export async function getSolveFn(moduleName: string) {
44
try {
55
const { default: solve } = await import(moduleName);
6-
if (typeof solve === "function") return solve as (input: string) => unknown;
6+
if (typeof solve !== "function") return;
7+
return solve as (input: string) => unknown | PromiseLike<unknown>;
78
} catch (e) {
89
console.warn(e);
910
return;

www/solver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function solvePart(
5656
}
5757
console.time("duration");
5858
try {
59-
const answer = solve(input);
59+
const answer = await solve(input);
6060
console.log("answer:", formatAnswer(answer, { dotLetterParsing }));
6161
} catch (e) {
6262
console.error(e);

0 commit comments

Comments
 (0)