워크 요청을 수행하고, 그에 대한 결과를 또 다른 콜백 함수로 전달합니다. 이러한 패턴은 세
번째 네트워크 요청까지 계속됩니다.
9.3
프로미스 패턴
프로미스
Promise
는 자바스크립트에서 비동기 작업을 처리하는 최신 방법입니다. 프로미스는
비동기 작업의 결과를 나타내는 객체로, 대기
pending
, 완료
fulfilled
, 거부
rejected
의 세 가지 상태를
가질 수 있습니다. 작업이 성공적으로 완료되었거나 거부되었을 때 결과를 제공하는 일종의
계약서 같은 존재입니다.
프로미스는
Promise
생성자를 사용하여 만들 수 있으며, 이 생성자는 함수를 인수로 받습니
다. 또다시 이 함수는
resolve
와
reject
두 개의 인수를 전달받습니다.
resolve
함수는 비
동기 작업이 성공적으로 완료되었을 때 호출되고,
reject
함수는 작업이 실패했을 때 호출
됩니다.
다음은 네트워크 요청을 위해 프로미스를 사용하는 방법을 보여주는 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.