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

খী awaitਸ ࠢ৓णפ׮  ੉ઁ ೣࣻח ೧׼ ೐۽޷झо resolveؼ ٸө૑ ӝ׮ܽ ٍ ׮਺ ۽૒ਵ۽ ֈযцפ׮

           ৘ܳ ٜݶ await	Users.findOne({})੉ resolveؼ ٸө૑ ӝ׮ܽ ׮਺ী user ߸ࣻܳ ୡӝചೞח Ѫੑפ׮

         ਤ ௏٘ח ী۞ܳ ୊ܻೞח ࠗ࠙ ೐۽޷झо rejectػ ҃਋ ੉ হਵ޲۽ ׮਺җ э਷ ୶о ੘স੉ ೙ਃ೤פ׮




           async	function	findAndSaveUser(Users)	{
           		try	{
           				let	user	=	await	Users.findOne({});
           				user.name	=	'zero';
           				user	=	await	user.save();
           				user	=	await	Users.findOne({	gender:	'm'	});
           				//	생략
           		}	catch	(error)	{
           				console.error(error);
           		}
           }




         try/catchޙਵ۽ ۽૒ਸ хसणפ׮  ೐۽޷झ੄ catch ݫࢲ٘୊ۢ try/catchޙ੄ catchо ী۞ܳ ୊ܻ೤פ

         ׮

         ച࢓಴ ೣࣻب BTZOD৬ э੉ ࢎਊೡ ࣻ ੓णפ׮




           const	findAndSaveUser	=	async	(Users)	=>	{
           		try	{
           				let	user	=	await	Users.findOne({});
           				user.name	=	'zero';
           				user	=	await	user.save();
           				user	=	await	Users.findOne({	gender:	'm'	});
           				//	생략
           		}	catch	(error)	{
           				console.error(error);
           		}
           };.




         forޙҗ async awaitਸ э੉ ॄࢲ ೐۽޷झܳ ࣽର੸ਵ۽ प೯ೡ ࣻ ੓णפ׮  forޙҗ ೣԋ ॳח Ѫ਷ ֢٘

         ߡ੹ࠗఠ ૑ਗೞח &4     ޙߨੑפ׮




           const	promise1	=	Promise.resolve('성공1');
           const	promise2	=	Promise.resolve('성공2');
   63   64   65   66   67   68   69   70   71   72   73