習慣上的寫法


Posted by mijouhsieh on 2023-05-01

outline:
Promise 物件實例中,

1 Promise 物件實例中,例子裡沒有設計 reject - catch 的段落,因此參數寫 _reject

在習慣上,加底線表示後面沒有用到這個參數。

 new Promise((resolve, _reject) => {
    for (const [user_index, user] of users.entries()) {
      // 創建使用者資料(user): model.create
      UserModel.create({
        ...user
      }).then((user) => {
        // 對每個user建立相對應餐廳資料
        return RestaurantModel.create(restaurants)
      }).then(() => {
        resolve()
      }).catch(error => {
        console.log(error)
      })
    }
  }).then(() => {
    // 等待所有使用者的餐廳資料創建完成
    console.log('所有使用者與餐廳資料創建完成')
    process.exit()
  })

#習慣上的寫法







Related Posts

排列組合 & 機率(Permutation, Combination & Probability)

排列組合 & 機率(Permutation, Combination & Probability)

學習 Git - 有些檔案想被 Git 忽略

學習 Git - 有些檔案想被 Git 忽略

原子習慣

原子習慣


Comments