Page 66 - Nodejs 교과서 개정2판
P. 66
.then((user) => {
user.name = 'zero';
return user.save();
})
.then((user) => {
return Users.findOne({ gender: 'm' });
})
.then((user) => {
// 생략
})
.catch(err => {
console.error(err);
});
}
٘ Өо ࣁ ױ҅ ࢚ Өয ঋणפ ਤ ٘ীࢲ then ݫࢲٜ٘ ࣽରਵ۽ प೯ؾפ ߔীࢲ
ݒߣ ٮ۽ ܻ೧ঠ ೮؍ ী۞ب ݄݃ catchীࢲ ೠ ߣী ܻೡ ࣻ णפ ೞ݅ ݽٚ ߔ ೣࣻܳ ਤ৬
э ߄Ե ࣻ ח Ѫ ইתפ ݫࢲ٘о ۽झ ߑधਸ ਗ೧ঠ פ
ઁ ٘ח findOneҗ save ݫࢲ٘о ղࠗਵ۽ ۽झ ёܳ оҊ Ҋ о೮ӝী оמפ ne
w Promiseо ೣࣻ ղࠗী ҳഅغয যঠ פ ਗೞ ঋח ҃ ߔ ೣࣻܳ ۽झ۽ ߄Ե ࣻ ח
ߑߨ ী ա৬ णפ
۽झ ৈ۞ ѐܳ ೠ ߣী प೯ೡ ࣻ ח ߑߨ णפ ӝઓ ߔ ಁఢݶ ߔਸ ৈ۞ ߣ ೧
ࢲ ࢎਊ೧ঠ ೮ਸ Ѫੑפ ೞ݅ Promise.allਸ ഝਊೞݶ рױ ೡ ࣻ णפ
const promise1 = Promise.resolve('성공1');
const promise2 = Promise.resolve('성공2');
Promise.all([promise1, promise2])
.then((result) => {
console.log(result); // ['성공1', '성공2'];
})
.catch((error) => {
console.error(error);
});
1SPNJTF SFTPMWFח द resolveೞח ۽झܳ ݅٘ח ߑߨੑפ ࠺तೠ Ѫਵ۽ द rejectೞח Promise
.rejectب णפ ۽झо ৈ۞ ѐ ਸ ٸ Promise.allী ֍ਵݶ ݽف resolveؼ ٸө ӝ۷о th
enਵ۽ ֈযцפ result ݒѐ߸ࣻী пп ۽झ ѾҞч ߓৌ۽ ٜয णפ Promise ೞաۄب
rejectо غݶ catch۽ ֈযцפ