File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed
Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ # 비동기 프로그래밍 패턴
2+
3+ > 저를 포함해 다 아시는 문법들을 알려주는 챕터였다고 생각됨
4+
5+ - 비동기 코드를 마치 동기 코드처럼 보이도록 작성할 수 있어 코드의 가독성과 이해도가 높아진다
6+ - async/await 문법의 이유
7+
8+ > 어싱크 어웨잇의 처음은 F#이라는 언어라네요
9+ > 이후에 C#, 파이썬, 타입스크립트, 자바스크립트 순으로 도입되었대요
10+
11+ ## 비동기 반복
12+
13+ - for await of
14+
15+ ``` js
16+ async function * repeat () {
17+ yield ' Hello' ;
18+ yield ' World' ;
19+ }
20+
21+ async function main () {
22+ for await (const word of repeat ()) {
23+ console .log (word);
24+ }
25+ }
26+ ```
27+
28+ ## 재시도
29+
30+ ``` js
31+ async function retry () {
32+ let attempt = 0 ;
33+
34+ while (attempt < 3 ) {
35+ try {
36+ return await fetch (' https://api.github.com' );
37+ } catch (err) {
38+ attempt++ ;
39+ }
40+ }
41+
42+ throw new Error (' Failed to fetch' );
43+ }
44+ ```
45+
46+ ## 데코레이터
47+
48+ ``` js
49+ const asyncLogger = (fn ) => {
50+ return async function (... args ) {
51+ console .log (' Start: ' , fn .name );
52+ const result = await fn (... args);
53+ console .log (' End: ' , fn .name );
54+ return result;
55+ };
56+ };
57+
58+ const main = asyncLogger (async function main () {
59+ return await new Promise (resolve => setTimeout (() => resolve (' user' ), 1000 ));
60+ });
61+
62+ main ();
63+ ```
64+
65+ > 책에서 나오는 ` @asyncLogger ` 데코레이터는 안됨 ㅋㅋㅋ 왜 적어둔거야
66+ > > 자바스크립트에서의 데코레이터는 현재 스테이지 3
67+ > > https://github.com/tc39/proposal-decorator-metadata
You can’t perform that action at this time.
0 commit comments