106 async/await 실행순서

source: categories/study/vue-experiance/vue-experiance_9-99_07.md

106 async/await 실행순서

const fs = require('fs/promises');
const constants = require('fs').constants;
const path = require('path');

(async () => {
    // await
    await fs.access(path.join(__dirname, 'dist/'), constants.F_OK | constants.W_OK | constants.R_OK) // 폴더 있는지 없는지 확인
        .then(() => {
            console.log('실행0')
        })
        .catch(async () => {
            await fs.mkdir(path.join(__dirname, 'dist/'));
        })
    
    // await
    await fs.access(path.join(__dirname, 'dist/ftl'), constants.F_OK | constants.W_OK | constants.R_OK) // 폴더 있는지 없는지 확인
        .then(() => {
            console.log('실행1')
        })
        .catch(async () => {
            await fs.mkdir(path.join(__dirname, 'dist/ftl'));
        })

    // await
    await fs.access(path.join(__dirname, 'dist/ftl/includes'), constants.F_OK | constants.W_OK | constants.R_OK) // 폴더 있는지 없는지 확인
        .then(() => {
            console.log('실행2')
        })
        .catch(async () => {
            await fs.mkdir(path.join(__dirname, 'dist/ftl/includes'));
        })

    console.log('실행3')
})()

// 실행0
// 실행1
// 실행2
// 실행3