v0.2.0
Library for denops plugin development. `defer` resolves combined multiple denops calls like `gather`.
Repository
Current version released
2 years ago
deno-denops-defer
defer
resolves combined multiple denops calls like gather
.
defer
preserves the structure of the complex object returned by the
executor
and resolves Promise it contains.
Example
To get expected
from the following input
:
const input = [
{ word: "foo" },
{ word: "hello" },
{ word: "πβ" },
];
const expected = [
{ word: "foo", bytes: 3 },
{ word: "hello", bytes: 5 },
{ word: "πβ", bytes: 7 },
]
Using defer
:
const output = await defer(denops, (helper) =>
input.map((item) => ({
...item,
bytes: strlen(helper, item.word) as Promise<number>,
})),
);
Using gather
(requires intermediate variable):
const intermediate = await gather(denops, async (helper) => {
for (const item of input) {
await strlen(helper, item.word);
}
}) as Promise<number[]>;
const output = input.map((item, index) => ({
...item,
bytes: intermediate[index],
}));