Skip to content

Commit f9ab988

Browse files
authored
Merge pull request #420 from vim-denops/fix-service
🐛 fix delay in resolving `waitLoaded()`
2 parents d3f43a2 + c0035db commit f9ab988

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

denops/@denops-private/service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,16 @@ export class Service implements HostService, AsyncDisposable {
9292
}
9393
}
9494

95-
async waitLoaded(name: string): Promise<void> {
96-
if (this.#closed) {
97-
throw new Error("Service closed");
95+
waitLoaded(name: string): Promise<void> {
96+
try {
97+
if (this.#closed) {
98+
throw new Error("Service closed");
99+
}
100+
assertValidPluginName(name);
101+
} catch (e) {
102+
return Promise.reject(e);
98103
}
99-
assertValidPluginName(name);
100-
await this.#getWaiter(name).promise;
104+
return this.#getWaiter(name).promise;
101105
}
102106

103107
interrupt(reason?: unknown): void {

denops/@denops-private/service_test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
assertRejects,
1111
assertStrictEquals,
1212
assertStringIncludes,
13-
assertThrows,
1413
} from "jsr:@std/assert@^1.0.1";
1514
import {
1615
assertSpyCall,
@@ -1236,22 +1235,23 @@ Deno.test("Service", async (t) => {
12361235
});
12371236

12381237
await t.step(".interrupt()", async (t) => {
1239-
await t.step("sends signal to `interrupted` attribute", () => {
1238+
await t.step("sends signal to `interrupted` property", () => {
12401239
const service = new Service(meta);
12411240
const signal = service.interrupted;
12421241

12431242
service.interrupt();
12441243

1245-
assertThrows(() => signal.throwIfAborted());
1244+
assert(signal.aborted);
12461245
});
12471246

1248-
await t.step("sends signal to `interrupted` attribute with reason", () => {
1247+
await t.step("sends signal to `interrupted` property with reason", () => {
12491248
const service = new Service(meta);
12501249
const signal = service.interrupted;
12511250

12521251
service.interrupt("test");
12531252

1254-
assertThrows(() => signal.throwIfAborted(), "test");
1253+
assert(signal.aborted);
1254+
assertEquals(signal.reason, "test");
12551255
});
12561256
});
12571257

0 commit comments

Comments
 (0)