diff --git a/_tools/check_docs.ts b/_tools/check_docs.ts index bfe267bb1..7e71ea5c9 100644 --- a/_tools/check_docs.ts +++ b/_tools/check_docs.ts @@ -22,6 +22,7 @@ import { type Location, type TsTypeDef, } from "@deno/doc"; +import { pooledMap } from "@std/async/pool"; type DocNodeWithJsDoc = T & { jsDoc: JsDoc; @@ -83,7 +84,7 @@ const ASSERTION_IMPORT = /from "@std\/(assert(\/[a-z-]+)?|testing\/(mock|snapshot|types))"/g; const NEWLINE = "\n"; const diagnostics: DocumentError[] = []; -const snippetPromises: Promise[] = []; +const snippetPromises: (() => Promise)[] = []; class DocumentError extends Error { constructor( @@ -246,11 +247,12 @@ function assertSnippetsWork( ); } snippetPromises.push( - assertSnippetEvals({ - snippet, - document, - expectError: delim?.includes("expect-error") ?? false, - }), + () => + assertSnippetEvals({ + snippet, + document, + expectError: delim?.includes("expect-error") ?? false, + }), ); } } @@ -528,13 +530,16 @@ if (!lintStatus.success) { Deno.exit(1); } -const promises = []; -for (const url of ENTRY_POINT_URLS) { - promises.push(checkDocs(url)); -} +await Promise.all(ENTRY_POINT_URLS.map(checkDocs)); -await Promise.all(promises); -await Promise.all(snippetPromises); +const iter = pooledMap( + navigator.hardwareConcurrency, + snippetPromises, + (fn) => fn(), +); +for await (const _ of iter) { + // noop +} if (diagnostics.length > 0) { for (const error of diagnostics) { console.error(