async-lib
内容物
promisify()
ある値を取り出してから次に取り出す間に生成された値の取り扱い方をoptionから変えられる
maxQueued
の値によらず、 resolve()
及び reject()
の第二引数に { forceQueued: true }
を渡すと間引かれない
pool()
sort()
/ sortBySettled()
当初は Iterable<Promise<T>>
を変換するつもりだったが、無限リストを入れられるとprogramが停止してしまうので、有限な配列に制限した
event listenerやmessage channelみたいなので上手いことやり取りすればいけるか?
いや、iteratorの消費を中断できないだろ
全部消費されるまで別の処理を行えない
実装したいこと
2022-04-18
18:20:35 pool
がちゃんと動いているのか疑問になったので、確かめてみる
テストは通っているから気にしなくても良さそうではあるが
18:27:17 特に問題はなさそうだった
tsimport { pool } from "./mod.ts";
import { getPage } from "../scrapbox-userscript-std/rest.ts";
import type { Scrapbox } from "../scrapbox-jp%2Ftypes/userscript.ts";
declare const scrapbox: Scrapbox;
let counter = 0;
const project = scrapbox.Project.name;
await Promise.all([...pool(
6,
scrapbox.Project.pages.filter((page) => page.exists),
async (page) => {
const index = counter++;
const result = await getPage(project, page.title);
console.log(`[${index} Download /${project}/${page.title}`);
},
)]);
mod.tsexport * from "https://raw.githubusercontent.com/takker99/async-lib/0.2.0/mod.ts";
export { delay as sleep } from "https://raw.githubusercontent.com/takker99/async-lib/0.2.0/delay.ts";