Page 64 - Nodejs 교과서 개정2판
P. 64

resolve('성공');
           		}	else	{
           				reject('실패');
           		}
           });
           //	다른	코드가	들어갈	수	있음
           promise
           		.then((message)	=>	{
           				console.log(message);	//	성공(resolve)한	경우	실행
           		})
           		.catch((error)	=>	{
           				console.error(error);	//	실패(reject)한	경우	실행
           		})
           		.finally(()	=>	{	//	끝나고	무조건	실행
           				console.log('무조건');
           });




         new	Promise۽ ೐۽޷झܳ ࢤࢿೡ ࣻ ੓ਵݴ  Ӓ ղࠗী resolve৬ rejectܳ ݒѐ߸ࣻ۽ ыח ௒ߔ ೣࣻܳ ֍
         णפ׮  ੉ۧѱ ݅ٚ promise ߸ࣻী thenҗ catch ݫࢲ٘ܳ ࠢੌ ࣻ ੓णפ׮  ೐۽޷झ ղࠗীࢲ resolveо

         ഐ୹غݶ then੉ प೯غҊ  rejectо ഐ୹غݶ catchо प೯ؾפ׮  finally ࠗ࠙਷ ࢿҕ पಁ ৈࠗ৬ ࢚ҙহ
         ੉ प೯ؾפ׮


         resolve৬ rejectী ֍যળ ੋࣻח пп thenҗ catch੄ ݒѐ߸ࣻীࢲ ߉ਸ ࣻ ੓णפ׮  ૊  resolve('성공'
         )੉ ഐ୹غݶ then੄ messageо '성공'੉ ؾפ׮  ݅ড reject('실패')о ഐ୹غݶ DBUDI੄ errorо '실패'

         о غח Ѫੑפ׮  condition ߸ࣻܳ false۽ ߄Լࠁݶ catchীࢲ ী۞о ۽Ӧؾפ׮

         ೐۽޷झܳ औѱ ࢸݺೞ੗ݶ  प೯਷ ߄۽ ೞغ ѾҞч਷ ա઺ী ߉ח ё୓ੑפ׮  ѾҞч਷ प೯੉ ৮ܐػ റ t

         hen੉ա catch ݫࢲ٘ܳ ా೧ ߉णפ׮  ਤ ৘ઁীࢲח new	Promise৬ promise.then ࢎ੉ী ׮ܲ ௏٘о ٜয

         т ࣻب ੓णפ׮  new	Promiseח ߄۽ प೯غ૑݅  ѾҞч਷ thenਸ ࠢ৓ਸ ٸ ߉ѱ ؾפ׮

         then੉ա catchীࢲ ׮द ׮ܲ UIFO੉ա catchܳ ࠢੌ ࣻ ੓णפ׮  ੉੹ then੄ return чਸ ׮਺ then੄ ݒ

         ѐ߸ࣻ۽ ֈӤפ׮  ೐۽޷झܳ returnೠ ҃਋ীח ೐۽޷झо ࣻ೯ػ റ ׮਺ UIFO੉ա catchо ഐ୹ؾפ׮




           promise
           		.then((message)	=>	{
           				return	new	Promise((resolve,	reject)	=>	{
           						resolve(message);
           				});
           		})
           		.then((message2)	=>	{
           				console.log(message2);
   59   60   61   62   63   64   65   66   67   68   69