import { collect } from "https://deno.land/x/denops_std@v6.5.0/batch/collect.ts";
Call multiple denops functions sequentially without RPC overhead and return values
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { collect } from "https://deno.land/x/denops_std@v6.5.0/batch/mod.ts";
export const main: Entrypoint = async (denops) => {
const results = await collect(denops, (denops) => [
denops.eval("&modifiable"),
denops.eval("&modified"),
denops.eval("&filetype"),
]);
// results contains the value of modifiable, modified, and filetype
}
Not like batch
, the function can NOT be nested.
Note that denops.call()
or denops.eval()
always return falsy value in
collect()
, indicating that you cannot write code like below:
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { collect } from "https://deno.land/x/denops_std@v6.5.0/batch/mod.ts";
export const main: Entrypoint = async (denops) => {
const results = await collect(denops, (denops) => {
// !!! DON'T DO THIS !!!
(async () => {
if (await denops.call("has", "nvim")) {
// deno-lint-ignore no-explicit-any
await (denops.call("api_info") as any).version;
} else {
await denops.eval("v:version");
}
})();
return [];
});
}
The denops
instance passed to the collect
block is NOT available outside of
the block. An error is thrown when denops.call()
, denops.cmd()
, or
denops.eval()
is called.
Note that denops.redraw()
and denops.cmd()
cannot be called within collect()
.
If it is called, an error is raised.