Skip to content

Commit cfab46e

Browse files
committed
🚿 Make batch() function in helper module deprecated
1 parent d749213 commit cfab46e

File tree

2 files changed

+14
-138
lines changed

2 files changed

+14
-138
lines changed

denops_std/helper/README.md

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -27,77 +27,8 @@ export async function main(denops: Denops): Promise<void> {
2727

2828
### batch
2929

30-
Use `batch()` to call multiple denops functions sequentially without overhead
31-
and get results like:
32-
33-
```typescript
34-
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
35-
import { batch } from "https://deno.land/x/denops_std/helper/mod.ts";
36-
37-
export async function main(denops: Denops): Promise<void> {
38-
const results = await batch(denops, (helper) => {
39-
helper.call("range", 2);
40-
helper.cmd("echomsg 'Hello'");
41-
helper.eval("v:version");
42-
});
43-
44-
console.log(results);
45-
// [
46-
// [0, 1],
47-
// 0,
48-
// '800',
49-
// ]
50-
}
51-
```
52-
53-
The `helper` instance implement `Denops` interface thus users can use it as
54-
`denops` like:
55-
56-
```typescript
57-
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
58-
import * as fn from "https://deno.land/x/denops_std/function/mod.ts";
59-
import * as vars from "https://deno.land/x/denops_std/variable/mod.ts";
60-
import { batch } from "https://deno.land/x/denops_std/helper/mod.ts";
61-
62-
export async function main(denops: Denops): Promise<void> {
63-
const results = await batch(denops, (helper) => {
64-
fn.range(helper, 2);
65-
vars.v.get(helper, "version");
66-
});
67-
68-
console.log(results);
69-
// [
70-
// [0, 1],
71-
// '800',
72-
// ]
73-
}
74-
```
75-
76-
When one of function call fails during batch process, `batch` throws
77-
`BatchError` which contains succeeded results as `results` like:
78-
79-
```typescript
80-
import { BatchError, Denops } from "https://deno.land/x/denops_std/mod.ts";
81-
import { batch } from "https://deno.land/x/denops_std/helper/mod.ts";
82-
83-
export async function main(denops: Denops): Promise<void> {
84-
try {
85-
await batch(denops, (helper) => {
86-
helper.call("range", 0);
87-
helper.call("range", 1);
88-
helper.call("no-such-function");
89-
helper.call("range", 2);
90-
});
91-
} catch (e) {
92-
// e is an instance of BatchErro
93-
if (e instanceof BatchError) {
94-
// Print succeeded results
95-
console.log("Succeeded:", e.results);
96-
}
97-
throw e;
98-
}
99-
}
100-
```
30+
Deprecated in favor of [`batch`](./batch/README.md) module. Use `gather()`
31+
function on that module instead.
10132

10233
### execute
10334

denops_std/helper/batch.ts

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,20 @@
1-
import { Context, Denops, Dispatcher, Meta } from "../deps.ts";
2-
3-
class BatchHelper implements Denops {
4-
#denops: Denops;
5-
#calls: [string, ...unknown[]][];
6-
7-
constructor(denops: Denops) {
8-
this.#denops = denops;
9-
this.#calls = [];
10-
}
11-
12-
static getCalls(helper: BatchHelper): [string, ...unknown[]][] {
13-
return helper.#calls;
14-
}
15-
16-
get name(): string {
17-
return this.#denops.name;
18-
}
19-
20-
get meta(): Meta {
21-
return this.#denops.meta;
22-
}
23-
24-
get dispatcher(): Dispatcher {
25-
return this.#denops.dispatcher;
26-
}
27-
28-
set dispatcher(dispatcher: Dispatcher) {
29-
this.#denops.dispatcher = dispatcher;
30-
}
31-
32-
call(fn: string, ...args: unknown[]): Promise<unknown> {
33-
this.#calls.push([fn, ...args]);
34-
return Promise.resolve();
35-
}
36-
37-
batch(..._calls: [string, ...unknown[]][]): Promise<unknown[]> {
38-
throw new Error(
39-
"The 'batch' method is not available on BatchDenops instance.",
40-
);
41-
}
42-
43-
cmd(cmd: string, ctx: Context = {}): Promise<void> {
44-
this.call("denops#api#cmd", cmd, ctx);
45-
return Promise.resolve();
46-
}
47-
48-
eval(expr: string, ctx: Context = {}): Promise<unknown> {
49-
this.call("denops#api#eval", expr, ctx);
50-
return Promise.resolve();
51-
}
52-
53-
dispatch(name: string, fn: string, ...args: unknown[]): Promise<unknown> {
54-
return this.#denops.dispatch(name, fn, ...args);
55-
}
56-
}
1+
import { Denops } from "../deps.ts";
2+
import { gather } from "../batch/mod.ts";
3+
import type { GatherHelper } from "../batch/mod.ts";
574

585
/**
59-
* Call denops functions sequentially without redraw and return the results.
60-
*
61-
* It is a wrapper function of `denops.batch()` to allow users to use `function`
62-
* modules, `denops.cmd()`, `denops.eval()`, or whatever things which assume a
63-
* `denops` instance.
6+
* @deprecated Use `gather()` function in `batch` module instead.
647
*/
658
export async function batch(
669
denops: Denops,
67-
main: (helper: BatchHelper) => Promise<void> | void,
10+
main: (helper: GatherHelper) => Promise<void> | void,
6811
): Promise<unknown[]> {
69-
const helper = new BatchHelper(denops);
70-
await main(helper);
71-
const calls = BatchHelper.getCalls(helper);
72-
return await denops.batch(...calls);
12+
console.warn(
13+
"DEPRECATED: Use `gather()` function in `batch` module instead.",
14+
);
15+
return await gather(denops, async (helper: GatherHelper) => {
16+
return await main(helper);
17+
});
7318
}
7419

75-
export type { BatchHelper };
20+
export type { GatherHelper as BatchHelper };

0 commit comments

Comments
 (0)