Skip to content

Commit 5d6645e

Browse files
committed
📝 Add clear documentation for differences between batch functions
1 parent c4da175 commit 5d6645e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

batch/mod.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
/**
22
* A module to provide `denops.batch()` helper functions
33
*
4+
* ## Functions Overview
5+
*
6+
* This module provides these functions for batching RPC calls, each serving different purposes:
7+
*
8+
* ### `batch()`
9+
* - **Purpose**: Manual batching for side-effects only (commands, settings)
10+
* - **Returns**: Always returns falsy values (void/undefined)
11+
* - **Use case**: When you need to execute multiple commands/settings without needing return values
12+
* - **Nesting**: Can be nested
13+
* - **Best for**: Most efficient when return values aren't needed
14+
*
15+
* ### `collect()`
16+
* - **Purpose**: Simple parallel value collection with type-safe returns
17+
* - **Returns**: Array of return values with proper types
18+
* - **Use case**: When you need to fetch multiple fixed values at once
19+
* - **Nesting**: Cannot be nested
20+
* - **Best for**: Cleanest API for fetching multiple values in parallel
21+
*
22+
* ### `accumulate()`
23+
* - **Purpose**: Automatic batching for complex async flows with loops and conditions
24+
* - **Returns**: Whatever the executor function returns
25+
* - **Use case**: When you need natural async/await code with automatic RPC optimization
26+
* - **Nesting**: Can be nested
27+
* - **Best for**: Complex flows with dynamic branching, loops, or conditional logic
28+
*
29+
* ## Choosing the Right Function
30+
*
31+
* - Use `batch()` when you only need to execute commands/settings and don't need return values
32+
* - Use `collect()` when you need to fetch multiple known values with clean, type-safe API
33+
* - Use `accumulate()` when you have complex async logic with conditionals, loops, or dynamic flows
34+
*
35+
* ## Examples
36+
*
437
* ```typescript
538
* import type { Entrypoint } from "jsr:@denops/std";
639
* import * as fn from "jsr:@denops/std/function";

0 commit comments

Comments
 (0)