Skip to content

Commit d3f43a2

Browse files
authored
Merge pull request #419 from vim-denops/asyncutil
🌿 use core/asyncutil instead lambdalisue/async
2 parents d0718c2 + 1dd064a commit d3f43a2

File tree

6 files changed

+48
-40
lines changed

6 files changed

+48
-40
lines changed

denops/@denops-private/cli_test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from "jsr:@std/testing@^1.0.0/mock";
2020
import { FakeTime } from "jsr:@std/testing@^1.0.0/time";
2121
import { delay } from "jsr:@std/async@^1.0.1/delay";
22-
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
22+
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
2323
import {
2424
createFakeTcpConn,
2525
createFakeTcpListener,
@@ -263,7 +263,7 @@ Deno.test("main()", async (t) => {
263263
});
264264

265265
await t.step("pendings main() Promise", async () => {
266-
assertEquals(await promiseState(p), "pending");
266+
assertEquals(await peekPromiseState(p), "pending");
267267
});
268268
});
269269

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

278278
await t.step("pendings main() Promise", async () => {
279-
assertEquals(await promiseState(p), "pending");
279+
assertEquals(await peekPromiseState(p), "pending");
280280
});
281281

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

298298
await t.step("resolves main() Promise", async () => {
299-
assertEquals(await promiseState(p), "fulfilled");
299+
assertEquals(await peekPromiseState(p), "fulfilled");
300300
});
301301
});
302302

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

386386
await t.step("pendings main() Promise", async () => {
387-
assertEquals(await promiseState(p), "pending");
387+
assertEquals(await peekPromiseState(p), "pending");
388388
});
389389

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

393394
await t.step("resolves main() Promise", async () => {
394-
assertEquals(await promiseState(p), "fulfilled");
395+
assertEquals(await peekPromiseState(p), "fulfilled");
395396
});
396397
});
397398
});
@@ -460,7 +461,7 @@ Deno.test("main()", async (t) => {
460461
});
461462

462463
await t.step("resolves main() Promise", async () => {
463-
assertEquals(await promiseState(p), "fulfilled");
464+
assertEquals(await peekPromiseState(p), "fulfilled");
464465
});
465466

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

606607
await t.step("resolves main() Promise", async () => {
607-
assertEquals(await promiseState(mainPromise), "fulfilled");
608+
assertEquals(await peekPromiseState(mainPromise), "fulfilled");
608609
});
609610
});
610611
});

denops/@denops-private/denops_test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
resolvesNext,
1313
stub,
1414
} from "jsr:@std/testing@^1.0.0/mock";
15-
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
15+
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
1616
import { DenopsImpl, type Host, type Service } from "./denops.ts";
1717

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

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

363-
assertEquals(await promiseState(dispatchPromise), "pending");
363+
assertEquals(await peekPromiseState(dispatchPromise), "pending");
364364
assertSpyCalls(service_waitLoaded, 1);
365365
assertSpyCalls(service_dispatch, 0);
366+
366367
waiter.resolve();
367-
assertEquals(await promiseState(dispatchPromise), "fulfilled");
368+
await flushPromises();
369+
370+
assertEquals(await peekPromiseState(dispatchPromise), "fulfilled");
368371
assertSpyCalls(service_waitLoaded, 1);
369372
assertSpyCalls(service_dispatch, 1);
370373
});

denops/@denops-private/host/nvim_test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
stub,
1212
} from "jsr:@std/testing@^1.0.0/mock";
1313
import { delay } from "jsr:@std/async@^1.0.1/delay";
14-
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
14+
import { peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
1515
import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0";
1616
import { Client } from "jsr:@lambdalisue/messagepack-rpc@^2.4.0";
1717
import { withNeovim } from "/denops-testutil/with.ts";
@@ -400,14 +400,14 @@ Deno.test("Neovim", async (t) => {
400400
const waitClosedPromise = host.waitClosed();
401401

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

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

409409
await t.step("fulfilled when the session closes", async () => {
410-
assertEquals(await promiseState(waitClosedPromise), "fulfilled");
410+
assertEquals(await peekPromiseState(waitClosedPromise), "fulfilled");
411411
});
412412
});
413413
},

denops/@denops-private/host/vim_test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
stub,
1111
} from "jsr:@std/testing@^1.0.0/mock";
1212
import { delay } from "jsr:@std/async@^1.0.1/delay";
13-
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
13+
import { peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
1414
import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0";
1515
import { Client, Session } from "jsr:@denops/vim-channel-command@^4.0.2";
1616
import { withVim } from "/denops-testutil/with.ts";
@@ -378,14 +378,14 @@ Deno.test("Vim", async (t) => {
378378
const waitClosedPromise = host.waitClosed();
379379

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

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

387387
await t.step("fulfilled when the session closes", async () => {
388-
assertEquals(await promiseState(waitClosedPromise), "fulfilled");
388+
assertEquals(await peekPromiseState(waitClosedPromise), "fulfilled");
389389
});
390390
});
391391
},

denops/@denops-private/service_test.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from "jsr:@std/testing@^1.0.0/mock";
2222
import { toFileUrl } from "jsr:@std/path@^1.0.2/to-file-url";
2323
import type { Meta } from "jsr:@denops/core@^7.0.0";
24-
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
24+
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
2525
import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0";
2626
import { INVALID_PLUGIN_NAMES } from "/denops-testdata/invalid_plugin_names.ts";
2727
import { resolveTestDataURL } from "/denops-testdata/resolve.ts";
@@ -644,7 +644,7 @@ Deno.test("Service", async (t) => {
644644
});
645645

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

650650
await t.step("emits `load()` and `unload()` events", () => {
@@ -691,7 +691,7 @@ Deno.test("Service", async (t) => {
691691
});
692692

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

697697
await t.step("outputs an error message", () => {
@@ -735,7 +735,7 @@ Deno.test("Service", async (t) => {
735735
});
736736

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

741741
await t.step("emits `unload()` events", () => {
@@ -930,7 +930,7 @@ Deno.test("Service", async (t) => {
930930
});
931931

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

936936
await t.step("emits `load()` and `reload()` events", () => {
@@ -993,7 +993,7 @@ Deno.test("Service", async (t) => {
993993
});
994994

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

999999
await t.step("emits `reload()` events", () => {
@@ -1132,7 +1132,7 @@ Deno.test("Service", async (t) => {
11321132

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

1135-
assertEquals(await promiseState(actual), "pending");
1135+
assertEquals(await peekPromiseState(actual), "pending");
11361136
});
11371137

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

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

1147-
assertEquals(await promiseState(actual), "pending");
1147+
assertEquals(await peekPromiseState(actual), "pending");
11481148
});
11491149

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

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

1158-
assertEquals(await promiseState(actual), "fulfilled");
1158+
assertEquals(await peekPromiseState(actual), "fulfilled");
11591159
});
11601160

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

1169-
assertEquals(await promiseState(actual), "fulfilled");
1169+
assertEquals(await peekPromiseState(actual), "fulfilled");
11701170
});
11711171

11721172
await t.step(
@@ -1181,7 +1181,7 @@ Deno.test("Service", async (t) => {
11811181
const unloadPromise = service.unload("dummy");
11821182
await Promise.all([loadPromise, unloadPromise]);
11831183

1184-
assertEquals(await promiseState(actual), "fulfilled");
1184+
assertEquals(await peekPromiseState(actual), "fulfilled");
11851185
},
11861186
);
11871187

@@ -1194,7 +1194,7 @@ Deno.test("Service", async (t) => {
11941194
const actual = service.waitLoaded("dummy");
11951195
actual.catch(NOOP);
11961196

1197-
assertEquals(await promiseState(actual), "rejected");
1197+
assertEquals(await peekPromiseState(actual), "rejected");
11981198
await assertRejects(
11991199
() => actual,
12001200
Error,
@@ -1211,7 +1211,7 @@ Deno.test("Service", async (t) => {
12111211
actual.catch(NOOP);
12121212
await service.close();
12131213

1214-
assertEquals(await promiseState(actual), "rejected");
1214+
assertEquals(await peekPromiseState(actual), "rejected");
12151215
await assertRejects(
12161216
() => actual,
12171217
Error,
@@ -1714,18 +1714,19 @@ Deno.test("Service", async (t) => {
17141714

17151715
const actual = service.waitClosed();
17161716

1717-
assertEquals(await promiseState(actual), "pending");
1717+
assertEquals(await peekPromiseState(actual), "pending");
17181718
});
17191719

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

17261727
const actual = service.waitClosed();
17271728

1728-
assertEquals(await promiseState(actual), "fulfilled");
1729+
assertEquals(await peekPromiseState(actual), "fulfilled");
17291730
});
17301731

17311732
await t.step("resolves when the service is closed", async () => {
@@ -1735,8 +1736,9 @@ Deno.test("Service", async (t) => {
17351736

17361737
const actual = service.waitClosed();
17371738
service.close();
1739+
await flushPromises();
17381740

1739-
assertEquals(await promiseState(actual), "fulfilled");
1741+
assertEquals(await peekPromiseState(actual), "fulfilled");
17401742
});
17411743
});
17421744

tests/denops/testutil/mock_test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
assertInstanceOf,
55
assertRejects,
66
} from "jsr:@std/assert@^1.0.1";
7-
import { promiseState } from "jsr:@lambdalisue/async@^2.1.1";
7+
import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1";
88
import {
99
createFakeTcpConn,
1010
createFakeTcpListener,
@@ -38,7 +38,7 @@ Deno.test("pendingPromise()", async (t) => {
3838
const actual = pendingPromise();
3939

4040
assertInstanceOf(actual, Promise);
41-
assertEquals(await promiseState(actual), "pending");
41+
assertEquals(await peekPromiseState(actual), "pending");
4242
});
4343
});
4444

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

9595
assertInstanceOf(promise, Promise);
96-
assertEquals(await promiseState(promise), "pending");
96+
assertEquals(await peekPromiseState(promise), "pending");
9797
});
9898
});
9999

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

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

107107
listener.close();
108+
await flushPromises();
108109

109-
assertEquals(await promiseState(resultPromise), "fulfilled");
110+
assertEquals(await peekPromiseState(resultPromise), "fulfilled");
110111
assertEquals(await resultPromise, {
111112
done: true,
112113
value: undefined,
@@ -142,11 +143,12 @@ Deno.test("createFakeTcpListener()", async (t) => {
142143
const resultPromise = iterator.next();
143144

144145
assertSpyCalls(listener_accept, 1);
145-
assertEquals(await promiseState(resultPromise), "pending");
146+
assertEquals(await peekPromiseState(resultPromise), "pending");
146147

147148
firstAcceptWaiter.resolve("fake-tcp-conn");
149+
await flushPromises();
148150

149-
assertEquals(await promiseState(resultPromise), "fulfilled");
151+
assertEquals(await peekPromiseState(resultPromise), "fulfilled");
150152
assertEquals(await resultPromise, {
151153
done: false,
152154
// deno-lint-ignore no-explicit-any

0 commit comments

Comments
 (0)