Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- github 100mb
- electron-packager
- adb connect
- animation
- camera access
- npm package
- Failed to compiled
- Git
- github lfs
- html
- adb pair
- ELECTRON
- 이미지 데이터 타입
- ffi-napi
- react-native
- silent printing
- vercel git lfs
- react-native-dotenv
- github pdf
- rolldown
- Each child in a list should have a unique "key" prop.
- Can't resolve
- nextjs
- 티스토리 성능
- device in use
- Recoil
- augmentedDevice
- dvh
- camera permission
- custom printing
Archives
- Today
- Total
Bleeding edge
순차적으로 비동기 실행시키기 본문
1. 사용할 배열을 선언한다.
const promiseStringArray = ["string1", "string2", "string3"];
2. 순차적으로 실행하기 위해서 reduce를 사용한다. 시작(initial Value)은 Promise.resolve()으로 시작한다
promiseStringArray.reduce(async(prev, current)=>{
}, Promise.resolve());
3. accumulator에 체이닝 준비한다.
const previousPromise = await prev.then();
4. 비동기를 실행한다.(예시함수 이름을 func로 사용하였다)
await func(current);
5. Promise로 체이닝을 건다.
return Promise.resolve(previousPromise)
모아보기
const promiseStringArray = ["string1", "string2", "string3"];
//promise 체이닝을 이용하기 위해 reduce를 사용한다.
promiseStringArray.reduce(async(prev, current)=>{
//이전에 사용할 체이닝을 준비한다.
const previousPromise = await prev.then();
//비동기를 실행한다
await func(current);
//promise chain을 연결한다.
return Promise.resolve(previousPromise)
//Promise.resolve로 시작한다
}, Promise.resolve());
'Javascript' 카테고리의 다른 글
prerendering page "/" ReferenceError: window is not defined (0) | 2023.10.21 |
---|---|
Axios로 간이 api mocking 세팅하기 (0) | 2023.08.14 |
환경에 따라 다른 서버로 Request 보내기 (0) | 2023.08.09 |
새로고침과 창끄기를 구분하는 방법 (0) | 2023.04.12 |
브라우저에서 로컬파일 여는 방법 (0) | 2023.01.25 |