Skip to content

Commit 1cbd77f

Browse files
committed
feat: dispose action after use
1 parent 4503d5d commit 1cbd77f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

denops/fall/lib/dispose.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,16 @@ export async function dispose(resource: unknown): Promise<void> {
2323
await resource[Symbol.asyncDispose]();
2424
}
2525
}
26+
27+
/**
28+
* Ensure the resource is async disposable.
29+
*/
30+
export function ensureAsyncDisposable<T>(resource: T): T & AsyncDisposable {
31+
if (isAsyncDisposable(resource)) {
32+
return resource as T & AsyncDisposable;
33+
}
34+
return {
35+
...resource,
36+
[Symbol.asyncDispose]: () => Promise.resolve(),
37+
};
38+
}

denops/fall/main/picker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
ItemPickerParams,
1717
} from "jsr:@vim-fall/std@^0.2.0/config";
1818

19+
import { ensureAsyncDisposable } from "../lib/dispose.ts";
1920
import {
2021
getActionPickerParams,
2122
getGlobalConfig,
@@ -183,6 +184,7 @@ async function startPicker(
183184
if (!action) {
184185
throw new Error(`Action "${actionName}" is not found`);
185186
}
187+
await using _guardAction = ensureAsyncDisposable(action);
186188
const actionParams = {
187189
// for 'submatch' action
188190
_submatchContext: {

0 commit comments

Comments
 (0)