mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Update
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { assertEquals } from "std/testing/asserts.ts";
|
||||
import { check_running } from "./pid_check.ts";
|
||||
import { promiseState, sleep } from "./utils.ts";
|
||||
import { asyncFilter, promiseState, PromiseStatus, sleep } from "./utils.ts";
|
||||
|
||||
Deno.test("promiseState_test", async () => {
|
||||
const p1 = new Promise((res) => setTimeout(() => res(100), 100));
|
||||
@@ -26,3 +26,19 @@ Deno.test("Pid_Test", async () => {
|
||||
assertEquals(await check_running(Deno.pid), true);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("asyncFilter_test", async () => {
|
||||
const t = [3, 5];
|
||||
const r = await asyncFilter(t, async (t) => {
|
||||
await sleep(10);
|
||||
return t === 3;
|
||||
});
|
||||
assertEquals(r, [3]);
|
||||
const e = [new Promise<number>((res) => setTimeout(() => res(100), 100))];
|
||||
const v = await asyncFilter(e, async (t) => {
|
||||
const s = await promiseState(t);
|
||||
return s.status === PromiseStatus.Pending;
|
||||
});
|
||||
assertEquals(v, e);
|
||||
await Promise.allSettled(e);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user