async_queue 패키지는 일련의 비동기 작업이 순차적으로 하나씩 실행되도록 보장하며, 순서를 유지하고 동시성 문제를 방지합니다. 작업 간 의존성 또는 실행 순서가 중요한 시나리오에 적합한 제어 가능한 방식으로 비동기 연산을 처리하기 위한 간단한 큐 메커니즘을 제공합니다. Dart로 개발되어 모든 주요 플랫폼에서 Flutter 프로젝트에 원활하게 통합됩니다. 가볍고 신뢰성에 중점을 둔 이 패키지는 백그라운드 처리, API 호출 시퀀싱, 또는 순서가 필요한 비동기 실행이 필요한 모든 사용 사례에 적합합니다.
사용 사례
순차적 API 호출
백그라운드 작업 처리
순서에 따라 달라지는 작업
비동기 작업을 포함한 상태 관리
순서대로 자산 로드
주요 기능
순차적 실행을 보장
간단한 큐 인터페이스
크로스 플랫폼 지원
경량이며 최소한의 종속성
스레드 안전 작업
적합한 대상
순서 있는 비동기 실행이 필요한 개발자
의존적인 비동기 워크플로우를 가진 앱
예측 가능한 작업 스케줄링이 필요한 프로젝트
다중 플랫폼을 대상으로 하는 Flutter 앱
코드 간결성을 우선시하는 팀
고려 사항
병렬 작업 실행용이 아님
인스턴스당 단일 대기열로 제한
큐 수명 주기의 신중한 관리가 필요합니다
작은에서 중간 규모의 작업 배치에 가장 적합
재시도 로직 또는 오류 복구를 처리하지 않음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Async Queue - ensure your list of async tasks execute in order
This dart package ensures your pack of async tasks executes in order, one after the other.
What's new in v3.0.0
addJob returns a Future — await individual job results directly, no more listener workarounds
Automatic retry on exceptions — jobs that throw are retried up to retryTime without manual retry() calls
onError callback — handle errors at the queue level: AsyncQueue(onError: (error, label) { ... })
Priority queue — addJob(..., priority: 10) to run important jobs first
final asyncQ = AsyncQueue();
asyncQ.addQueueListener((event) => print("$event"));
Await job result (v3.0.0+)
addJob returns a Future that completes with the job's return value. This works alongside previousResult — they serve different purposes.
final q = AsyncQueue.autoStart();
// Each addJob returns a Future you can await for its resultfinal userFuture = q.addJob((_) async {
returnawait api.getUser(); // returns "Sam"
});
// previousResult still chains between jobsfinal postsFuture = q.addJob((previousResult) async {
returnawait api.getPostsFor(previousResult);
});
final user = await userFuture; // "Sam"final posts = await postsFuture; // [Post, Post, ...]
Automatic retry on exceptions (v3.0.0+)
Jobs that throw are automatically retried up to retryTime times. You no longer need to catch errors and call retry() manually (though you still can for custom logic).
q.addJob((_) async {
// if this throws, it will be retried automaticallyreturnawait api.fetchData();
}, retryTime: 3);
onError callback (v3.0.0+)
Handle errors at the queue level without parsing events:
This package would be useful if you have multiple widgets in a screen or even in multiple screens that need to do some async requests that are related to each other.
For examples:
To make one request from a widget wait for another request from another widget to finish.
To avoid multiple requests from the front end hitting the backend in a short time, which would confuse the backend.