Skip to content

Commit

Permalink
Merge pull request #420 from vim-denops/fix-service
Browse files Browse the repository at this point in the history
🐛 fix delay in resolving `waitLoaded()`
  • Loading branch information
lambdalisue authored Sep 18, 2024
2 parents d3f43a2 + c0035db commit f9ab988
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions denops/@denops-private/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ export class Service implements HostService, AsyncDisposable {
}
}

async waitLoaded(name: string): Promise<void> {
if (this.#closed) {
throw new Error("Service closed");
waitLoaded(name: string): Promise<void> {
try {
if (this.#closed) {
throw new Error("Service closed");
}
assertValidPluginName(name);
} catch (e) {
return Promise.reject(e);
}
assertValidPluginName(name);
await this.#getWaiter(name).promise;
return this.#getWaiter(name).promise;
}

interrupt(reason?: unknown): void {
Expand Down
10 changes: 5 additions & 5 deletions denops/@denops-private/service_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
assertRejects,
assertStrictEquals,
assertStringIncludes,
assertThrows,
} from "jsr:@std/assert@^1.0.1";
import {
assertSpyCall,
Expand Down Expand Up @@ -1236,22 +1235,23 @@ Deno.test("Service", async (t) => {
});

await t.step(".interrupt()", async (t) => {
await t.step("sends signal to `interrupted` attribute", () => {
await t.step("sends signal to `interrupted` property", () => {
const service = new Service(meta);
const signal = service.interrupted;

service.interrupt();

assertThrows(() => signal.throwIfAborted());
assert(signal.aborted);
});

await t.step("sends signal to `interrupted` attribute with reason", () => {
await t.step("sends signal to `interrupted` property with reason", () => {
const service = new Service(meta);
const signal = service.interrupted;

service.interrupt("test");

assertThrows(() => signal.throwIfAborted(), "test");
assert(signal.aborted);
assertEquals(signal.reason, "test");
});
});

Expand Down

0 comments on commit f9ab988

Please sign in to comment.