lllbatch
v1.0.5
Published
- [github](https://github.com/LLL-Studio/LLLBatch) - [npm](https://www.npmjs.com/package/lllbatch)
Downloads
659
Readme
LLLBatch
Smart Async Concurrency Control & Batch Processor with Zero Dependencies. 의존성 제로, 설정 파일 기반의 초경량 비동기 동시성 제어 및 배치 처리기
⚡ Features
📦 ESM Native Only: Designed exclusively for modern ECMAScript Modules (import/export).
⚙️ Config-Driven: Automatically detects and loads lllbatch.config.js from your root folder.
🔥 Rolling Window Queue: High-throughput execution. Next task starts immediately when one finishes, instead of waiting for the entire chunk.
🛡️ Bulletproof: If one task fails, it safely catches the error and continues the rest of the queue.
🚀 Installation / 설치
npm install lllbatch⚠️ Prerequisite / 필수 조건: This Package is ESM-only. Ensure "type": "module" is set in your package.json.
본 패키지는 ESM 전용입니다. package.json에 "type": "module"이 설정되어 있어야 합니다.
🛠️ Configuration / 설정 방법
Create a lllbatch.config.js file in your project root to set global options.
프로젝트 루트 폴더에 lllbatch.config.js 파일을 생성하여 전역 설정을 관리할 수 있습니다.
// lllbatch.config.js
export default {
concurrency: 5 // Max parallel workers (Default: 3) / 동시에 처리할 최대 작업 수
};💻 Usage / 사용법
🇺🇸 English Guide
You can batch process arrays with a rolling concurrency pool. Inline options always override the global configuration file.
import { batch } from 'lllbatch';
// Simulate an async task that takes 1 second
const mockTask = (id) => new Promise(resolve => setTimeout(() => resolve(`Result ${id}`), 1000));
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// 1. Using global configuration (e.g., 5 from lllbatch.config.js)
const results = await batch(items, async (id) => {
return await mockTask(id);
});
// 2. Overriding inline (Dynamically change concurrency to 10)
const fastResults = await batch(items, async (id) => {
return await mockTask(id);
}, { concurrency: 10 });🇰🇷 한국어 가이드
배열 데이터와 비동기 함수를 던지면 설정된 개수만큼 끊어서 효율적으로 실행합니다. 코드 내부에 직접 명시한 인라인 옵션은 설정 파일보다 우선순위가 높습니다.
import { batch } from 'lllbatch';
// 1초가 걸리는 가짜 비동기 태스크
const mockTask = (id) => new Promise(resolve => setTimeout(() => resolve(`결과 ${id}`), 1000));
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// 1. 전역 설정 파일 적용 (lllbatch.config.js에 적힌 개수대로 실행)
const results = await batch(items, async (id) => {
return await mockTask(id);
});
// 2. 인라인 옵션으로 뭉개기 (순간적으로 동시성을 10으로 올려서 초고속 처리)
const fastResults = await batch(items, async (id) => {
return await mockTask(id);
}, { concurrency: 10 });📊 API Reference
batch(items, fn, options?)
Parameters
items(Array): An array of data to process. / 처리할 데이터 배열.fn(Function): Async callback function executed for each item. Receives(item, index). / 각 아이템을 처리할 비동기 콜백 함수.options(Object, optional):concurrency(number): Overrides the default or configured max parallel worker limit. / 전역 설정을 무시하고 동시 실행 수를 직접 지정.
Return Value
- Returns a
Promiseresolving to an array of results. If a task throws an error, the specific index in the array will contain theErrorobject instead of crashing the whole batch. - 실행 결과 배열을 담은
Promise를 반환합니다. 특정 작업에서 에러가 발생하더라도 전체 프로세스가 터지지 않고, 해당 인덱스에Error객체가 안전하게 담깁니다.
📄 License
MIT © lll-ecosystem
