본문 바로가기
프로그래밍

TIL - 200625

by Youngbin Kwon 2020. 6. 25.

1. 배운 것

Codecademy - Learn Javascript : Promise

 

프로미스 : JavaScript는 엔진은 Single Thread이다. 그래서 동시에 두 가지 작업을 할 수 없다. 그렇다면 여러 작업이 동시에 요청이 될 때 이 전 작업이 마무리 될 때까지 기다려야 하는가? 그래서 JavaScript 엔진은 비동기 처리가 가능하도록 설계되었다.

 

JavaScript에서 Promise는 비동기적으로 실행하는 작업의 결과(성공 or 실패)를 나타내는 객체이다. 여기서 주목해야 하는 점은 객체 라는 것인데, 비동기의 결과를 객체화 시킨다는 점이 Promise의 가장 큰 장점이자 특징이 된다.

 

  • Promises are JavaScript objects that represent the eventual result of an asynchronous operation.
  • Promises can be in one of three states: pending, resolved, or rejected.
  • A promise is settled if it is either resolved or rejected.
  • We construct a promise by using the new keyword and passing an executor function to the Promise constructor method.
  • setTimeout() is a Node function which delays the execution of a callback function using the event-loop.
  • We use .then() with a success handler callback containing the logic for what should happen if a promise resolves.
  • We use .catch() with a failure handler callback containing the logic for what should happen if a promise rejects.
  • Promise composition enables us to write complex, asynchronous code that’s still readable. We do this by chaining multiple .then()‘s and .catch()‘s.
  • To use promise composition correctly, we have to remember to return promises constructed within a .then().
  • We should chain multiple promises rather than nesting them.
  • To take advantage of concurrency, we can use Promise.all().

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise

 

Promise

Promise 객체는 비동기 작업이 맞이할 미래의 완료 또는 실패와 그 결과 값을 나타냅니다.

developer.mozilla.org

https://programmingsummaries.tistory.com/325

 

[JavaScript] 바보들을 위한 Promise 강의 - 도대체 Promise는 어떻게 쓰는거야?

들어가며 JavaScript의 세계에서는 거의 대부분의 작업들이 비동기로 이루어진다. 어떤 작업을 요청하면서 콜백 함수를 등록하면, 작업이 수행되고 나서 결과를 나중에 콜백 함수를 통해 알려주는

programmingsummaries.tistory.com

https://velog.io/@cyranocoding/2019-08-02-1808-%EC%9E%91%EC%84%B1%EB%90%A8-5hjytwqpqj

 

JavaScript 비동기 처리를 위한 promise 이해하기

배경지식 JavaScript는 엔진은 Single Thread이다. 그래서 동시에 두 가지 작업을 할 수 없다. 그렇다면 여러 작업이 동시에 요청이 될 때 이 전 작업이 마무리 될 때까지 기다려야 하는가? 그렇다. 그래

velog.io

2. 개발한 것

 -

 

3. 개발할 것

 1) Codecademy JS 강의 : Async-await

'프로그래밍' 카테고리의 다른 글

wecode 사전스터디 1주차(7/16) 로그  (0) 2020.07.16
wecode 사전스터디 1주차(7/13) 로그  (0) 2020.07.15
TIL - 200623  (0) 2020.06.24
TIL - 200615  (0) 2020.06.16
TIL - 200614  (0) 2020.06.16

댓글