Skip to content

Commit

Permalink
🌿 use core/asyncutil instead lambdalisue/async
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Sep 15, 2024
1 parent aed70a1 commit 1dd064a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
17 changes: 9 additions & 8 deletions denops/@denops-private/cli_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "jsr:@std/testing@^1.0.0/mock";
import { FakeTime } from "jsr:@std/testing@^1.0.0/time";
import { delay } from "jsr:@std/async@^1.0.1/delay";
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
import {
createFakeTcpConn,
createFakeTcpListener,
Expand Down Expand Up @@ -263,7 +263,7 @@ Deno.test("main()", async (t) => {
});

await t.step("pendings main() Promise", async () => {
assertEquals(await promiseState(p), "pending");
assertEquals(await peekPromiseState(p), "pending");
});
});

Expand All @@ -276,7 +276,7 @@ Deno.test("main()", async (t) => {
});

await t.step("pendings main() Promise", async () => {
assertEquals(await promiseState(p), "pending");
assertEquals(await peekPromiseState(p), "pending");
});

await t.step(
Expand All @@ -296,7 +296,7 @@ Deno.test("main()", async (t) => {
});

await t.step("resolves main() Promise", async () => {
assertEquals(await promiseState(p), "fulfilled");
assertEquals(await peekPromiseState(p), "fulfilled");
});
});

Expand Down Expand Up @@ -384,14 +384,15 @@ Deno.test("main()", async (t) => {
});

await t.step("pendings main() Promise", async () => {
assertEquals(await promiseState(p), "pending");
assertEquals(await peekPromiseState(p), "pending");
});

await t.step("and the listner is closed", async (t) => {
fakeTcpListener.close();
await flushPromises();

await t.step("resolves main() Promise", async () => {
assertEquals(await promiseState(p), "fulfilled");
assertEquals(await peekPromiseState(p), "fulfilled");
});
});
});
Expand Down Expand Up @@ -460,7 +461,7 @@ Deno.test("main()", async (t) => {
});

await t.step("resolves main() Promise", async () => {
assertEquals(await promiseState(p), "fulfilled");
assertEquals(await peekPromiseState(p), "fulfilled");
});

await t.step("does not outputs error logs", () => {
Expand Down Expand Up @@ -604,7 +605,7 @@ Deno.test("main()", async (t) => {
});

await t.step("resolves main() Promise", async () => {
assertEquals(await promiseState(mainPromise), "fulfilled");
assertEquals(await peekPromiseState(mainPromise), "fulfilled");
});
});
});
Expand Down
9 changes: 6 additions & 3 deletions denops/@denops-private/denops_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
resolvesNext,
stub,
} from "jsr:@std/testing@^1.0.0/mock";
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
import { DenopsImpl, type Host, type Service } from "./denops.ts";

type BatchReturn = [results: unknown[], errmsg: string];
Expand Down Expand Up @@ -360,11 +360,14 @@ Deno.test("DenopsImpl", async (t) => {

const dispatchPromise = denops.dispatch("dummy", "fn", "args");

assertEquals(await promiseState(dispatchPromise), "pending");
assertEquals(await peekPromiseState(dispatchPromise), "pending");
assertSpyCalls(service_waitLoaded, 1);
assertSpyCalls(service_dispatch, 0);

waiter.resolve();
assertEquals(await promiseState(dispatchPromise), "fulfilled");
await flushPromises();

assertEquals(await peekPromiseState(dispatchPromise), "fulfilled");
assertSpyCalls(service_waitLoaded, 1);
assertSpyCalls(service_dispatch, 1);
});
Expand Down
6 changes: 3 additions & 3 deletions denops/@denops-private/host/nvim_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
stub,
} from "jsr:@std/testing@^1.0.0/mock";
import { delay } from "jsr:@std/async@^1.0.1/delay";
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
import { peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0";
import { Client } from "jsr:@lambdalisue/messagepack-rpc@^2.4.0";
import { withNeovim } from "/denops-testutil/with.ts";
Expand Down Expand Up @@ -400,14 +400,14 @@ Deno.test("Neovim", async (t) => {
const waitClosedPromise = host.waitClosed();

await t.step("pendings before the session closes", async () => {
assertEquals(await promiseState(waitClosedPromise), "pending");
assertEquals(await peekPromiseState(waitClosedPromise), "pending");
});

// NOTE: Close the session of the host.
await host[Symbol.asyncDispose]();

await t.step("fulfilled when the session closes", async () => {
assertEquals(await promiseState(waitClosedPromise), "fulfilled");
assertEquals(await peekPromiseState(waitClosedPromise), "fulfilled");
});
});
},
Expand Down
6 changes: 3 additions & 3 deletions denops/@denops-private/host/vim_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
stub,
} from "jsr:@std/testing@^1.0.0/mock";
import { delay } from "jsr:@std/async@^1.0.1/delay";
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
import { peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0";
import { Client, Session } from "jsr:@denops/vim-channel-command@^4.0.2";
import { withVim } from "/denops-testutil/with.ts";
Expand Down Expand Up @@ -378,14 +378,14 @@ Deno.test("Vim", async (t) => {
const waitClosedPromise = host.waitClosed();

await t.step("pendings before the session closes", async () => {
assertEquals(await promiseState(waitClosedPromise), "pending");
assertEquals(await peekPromiseState(waitClosedPromise), "pending");
});

// NOTE: Close the session of the host.
await host[Symbol.asyncDispose]();

await t.step("fulfilled when the session closes", async () => {
assertEquals(await promiseState(waitClosedPromise), "fulfilled");
assertEquals(await peekPromiseState(waitClosedPromise), "fulfilled");
});
});
},
Expand Down
34 changes: 18 additions & 16 deletions denops/@denops-private/service_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "jsr:@std/testing@^1.0.0/mock";
import { toFileUrl } from "jsr:@std/path@^1.0.2/to-file-url";
import type { Meta } from "jsr:@denops/core@^7.0.0";
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0";
import { resolveTestDataURL } from "/denops-testdata/resolve.ts";
import type { Host } from "./denops.ts";
Expand Down Expand Up @@ -621,7 +621,7 @@ Deno.test("Service", async (t) => {
});

await t.step("previous `load()` was resolved", async () => {
assertEquals(await promiseState(prevLoadPromise), "fulfilled");
assertEquals(await peekPromiseState(prevLoadPromise), "fulfilled");
});

await t.step("emits `load()` and `unload()` events", () => {
Expand Down Expand Up @@ -668,7 +668,7 @@ Deno.test("Service", async (t) => {
});

await t.step("previous `load()` was resolved", async () => {
assertEquals(await promiseState(prevLoadPromise), "fulfilled");
assertEquals(await peekPromiseState(prevLoadPromise), "fulfilled");
});

await t.step("outputs an error message", () => {
Expand Down Expand Up @@ -712,7 +712,7 @@ Deno.test("Service", async (t) => {
});

await t.step("previous `unload()` was resolved", async () => {
assertEquals(await promiseState(prevUnloadPromise), "fulfilled");
assertEquals(await peekPromiseState(prevUnloadPromise), "fulfilled");
});

await t.step("emits `unload()` events", () => {
Expand Down Expand Up @@ -887,7 +887,7 @@ Deno.test("Service", async (t) => {
});

await t.step("previous `load()` was resolved", async () => {
assertEquals(await promiseState(prevLoadPromise), "fulfilled");
assertEquals(await peekPromiseState(prevLoadPromise), "fulfilled");
});

await t.step("emits `load()` and `reload()` events", () => {
Expand Down Expand Up @@ -950,7 +950,7 @@ Deno.test("Service", async (t) => {
});

await t.step("previous `unload()` was resolved", async () => {
assertEquals(await promiseState(prevUnloadPromise), "fulfilled");
assertEquals(await peekPromiseState(prevUnloadPromise), "fulfilled");
});

await t.step("emits `reload()` events", () => {
Expand Down Expand Up @@ -1069,7 +1069,7 @@ Deno.test("Service", async (t) => {

const actual = service.waitLoaded("dummy");

assertEquals(await promiseState(actual), "pending");
assertEquals(await peekPromiseState(actual), "pending");
});

await t.step("pendings if the plugin is already unloaded", async () => {
Expand All @@ -1081,7 +1081,7 @@ Deno.test("Service", async (t) => {

const actual = service.waitLoaded("dummy");

assertEquals(await promiseState(actual), "pending");
assertEquals(await peekPromiseState(actual), "pending");
});

await t.step("resolves if the plugin is already loaded", async () => {
Expand All @@ -1092,7 +1092,7 @@ Deno.test("Service", async (t) => {

const actual = service.waitLoaded("dummy");

assertEquals(await promiseState(actual), "fulfilled");
assertEquals(await peekPromiseState(actual), "fulfilled");
});

await t.step("resolves when the plugin is loaded", async () => {
Expand All @@ -1103,7 +1103,7 @@ Deno.test("Service", async (t) => {
const actual = service.waitLoaded("dummy");
await service.load("dummy", scriptValid);

assertEquals(await promiseState(actual), "fulfilled");
assertEquals(await peekPromiseState(actual), "fulfilled");
});

await t.step(
Expand All @@ -1118,7 +1118,7 @@ Deno.test("Service", async (t) => {
const unloadPromise = service.unload("dummy");
await Promise.all([loadPromise, unloadPromise]);

assertEquals(await promiseState(actual), "fulfilled");
assertEquals(await peekPromiseState(actual), "fulfilled");
},
);

Expand All @@ -1131,7 +1131,7 @@ Deno.test("Service", async (t) => {
const actual = service.waitLoaded("dummy");
actual.catch(NOOP);

assertEquals(await promiseState(actual), "rejected");
assertEquals(await peekPromiseState(actual), "rejected");
await assertRejects(
() => actual,
Error,
Expand All @@ -1147,7 +1147,7 @@ Deno.test("Service", async (t) => {
const actual = service.waitLoaded("dummy");
await service.close();

assertEquals(await promiseState(actual), "rejected");
assertEquals(await peekPromiseState(actual), "rejected");
await assertRejects(
() => actual,
Error,
Expand Down Expand Up @@ -1586,18 +1586,19 @@ Deno.test("Service", async (t) => {

const actual = service.waitClosed();

assertEquals(await promiseState(actual), "pending");
assertEquals(await peekPromiseState(actual), "pending");
});

await t.step("resolves if the service is already closed", async () => {
using _host_call = stub(host, "call");
const service = new Service(meta);
service.bind(host);
service.close();
await flushPromises();

const actual = service.waitClosed();

assertEquals(await promiseState(actual), "fulfilled");
assertEquals(await peekPromiseState(actual), "fulfilled");
});

await t.step("resolves when the service is closed", async () => {
Expand All @@ -1607,8 +1608,9 @@ Deno.test("Service", async (t) => {

const actual = service.waitClosed();
service.close();
await flushPromises();

assertEquals(await promiseState(actual), "fulfilled");
assertEquals(await peekPromiseState(actual), "fulfilled");
});
});

Expand Down
16 changes: 9 additions & 7 deletions tests/denops/testutil/mock_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertInstanceOf,
assertRejects,
} from "jsr:@std/assert@^1.0.1";
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
import {
createFakeTcpConn,
createFakeTcpListener,
Expand Down Expand Up @@ -38,7 +38,7 @@ Deno.test("pendingPromise()", async (t) => {
const actual = pendingPromise();

assertInstanceOf(actual, Promise);
assertEquals(await promiseState(actual), "pending");
assertEquals(await peekPromiseState(actual), "pending");
});
});

Expand Down Expand Up @@ -93,7 +93,7 @@ Deno.test("createFakeTcpListener()", async (t) => {
const promise = listener.accept();

assertInstanceOf(promise, Promise);
assertEquals(await promiseState(promise), "pending");
assertEquals(await peekPromiseState(promise), "pending");
});
});

Expand All @@ -102,11 +102,12 @@ Deno.test("createFakeTcpListener()", async (t) => {
const resultPromise = iterator.next();

await t.step("closes the conn iterator", async () => {
assertEquals(await promiseState(resultPromise), "pending");
assertEquals(await peekPromiseState(resultPromise), "pending");

listener.close();
await flushPromises();

assertEquals(await promiseState(resultPromise), "fulfilled");
assertEquals(await peekPromiseState(resultPromise), "fulfilled");
assertEquals(await resultPromise, {
done: true,
value: undefined,
Expand Down Expand Up @@ -142,11 +143,12 @@ Deno.test("createFakeTcpListener()", async (t) => {
const resultPromise = iterator.next();

assertSpyCalls(listener_accept, 1);
assertEquals(await promiseState(resultPromise), "pending");
assertEquals(await peekPromiseState(resultPromise), "pending");

firstAcceptWaiter.resolve("fake-tcp-conn");
await flushPromises();

assertEquals(await promiseState(resultPromise), "fulfilled");
assertEquals(await peekPromiseState(resultPromise), "fulfilled");
assertEquals(await resultPromise, {
done: false,
// deno-lint-ignore no-explicit-any
Expand Down

0 comments on commit 1dd064a

Please sign in to comment.