|
1 | 1 | /** |
2 | 2 | * A module to provide `denops.batch()` helper functions |
3 | 3 | * |
| 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 | + * |
4 | 37 | * ```typescript |
5 | 38 | * import type { Entrypoint } from "jsr:@denops/std"; |
6 | 39 | * import * as fn from "jsr:@denops/std/function"; |
|
0 commit comments