Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
/ deno-denops-defer Public archive

Library for denops plugin development. `defer` resolves combined multiple denops calls like `gather`.

License

Notifications You must be signed in to change notification settings

Milly/deno-denops-defer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ARCHIVED

Use denops-batch-accumulate.

deno-denops-defer

license:MIT deno land

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],
}));

About

Library for denops plugin development. `defer` resolves combined multiple denops calls like `gather`.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published