Skip to content

Commit

Permalink
[docs] 完善 asyncArrayFn 工具方法文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang-Wei-666 committed Aug 7, 2023
1 parent bc77a76 commit 6bcd286
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/mixte/src/asyncArrayFn/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
异步地遍历数组, 并对每个元素执行回调函数

### 类型

```ts
/**
* 异步地遍历数组, 并对每个元素执行回调函数
*
* @param array 要遍历的数组
* @param callback 对每个元素执行的回调函数, 它接受三个参数: `value`, `index` 和 `array`, 回调函数可以是异步的, 可以返回一个 Promise 或一个值
*/
function asyncForEach<T>(
array: T[],
callback: (value: T, index: number, array: T[]) => Promisable<any>
): Promise<void>;
```

### 示例

```ts
import { asyncForEach } from 'mixte';

const array = [1, 2, 3, 4, 5];

await asyncForEach(array, async (value, index, array) => {
console.log(`正在处理索引为 ${index} 的元素 ${value}`);
await someAsyncOperation(value);
console.log(`元素 ${value} 处理完毕`);
});

console.log('所有元素已处理完毕');
```

0 comments on commit 6bcd286

Please sign in to comment.